Hi guys, can you tell me what i can do to this piece of java script so that the turrets which fire the bullets fire automatically and only when your character is in site. So far the turret aims at my player and shoots at my player when i press space bar.
// Instantiates a projectile every 0.1 seconds,
// if the Fire1 button is pressed or held down.
var projectile : Rigidbody;
var fireRate = 0.5;
var Velocity : float = 25;
private var nextFire = 0.0;
function Update () {
//If the player holds down or presses the left mouse button
if (Input.GetButton ("Jump") && Time.time > nextFire) {
Shoot();
}
}
//To make our scripting a little more Object-Oriented-Programming, we will create our custom functions as well
function Shoot() {
//Add fireRate and current time to nextFire
nextFire = Time.time + fireRate;
//Instantiate the projectile
clone = Instantiate (projectile, transform.position, transform.rotation);
//Name the clone "Shot" ::: this name will appear in the Hierarchy View when you Instantiate the object
clone.name = "Shot";
//Add speed to the target
clone.rigidbody.velocity = transform.TransformDirection (Vector3.forward * Velocity);
}
Thanks, Easy points