Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Firing to Target In Range

$
0
0
I'm creating an arcade game and I created some turrets called "turbolaser". I created a script for these turrets to shoot continously with 1 sec. wait before firing again. No problems occured; here's the script: #pragma strict var shot : GameObject; var shotSpawn : Transform; var fireRate : float; private var nextFire : float; function Update () { if (Time.time > nextFire) { nextFire = Time.time + fireRate; Instantiate(shot, shotSpawn.position, shotSpawn.rotation); } } But then, I tried to stop them from shooting when the player is too far, and configured the script but it didn't work: #pragma strict var shot : GameObject; var shotSpawn : Transform; var fireRate : float; var distance : float; var player : Transform; var turbolaser : Transform; private var nextFire : float; function Update () { distance = Vector3.Distance (player - turbolaser); if (Time.time > nextFire) { if(distance <= 20.0f){ nextFire = Time.time + fireRate; Instantiate(shot, shotSpawn.position, shotSpawn.rotation); } } } Then I get this error: Operator "-" cannot be used with a left hand side of type UnityEngine.transform and a right hand side of type UnityEngine.transform. I understand what the error is telling me, but what should I do ?

Viewing all articles
Browse latest Browse all 7934

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>