//bullet script
//Inspector variables
var bulletSpeed : float = 15.0; // Speed of bullet
var bulletLimit : float = 10.0; // where will bullet dissapear
var explosion : Transform;
var sceneManager: GameObject; // load manager script for scoring
//Private Variable
// Game loop
function Update ()
{
transform.Translate(0,bulletSpeed*Time.deltaTime,0);
// check if object is off screen
if (transform.position.y>= bulletLimit)
{
Destroy (gameObject);
}
}
function OnTriggerEnter (other :Collider)
{
// check for asteriod
if (other.gameObject.tag =="astroid")
{
//reset enermy position
other.transform.position.y = 10.0;
other.transform.position.x = Random.Range(-10,10);
// explosion on impact
if (explosion)
{
Instantiate (explosion,transform.position,transform.rotation);
}
// Tell score manager that enery is destroy and to add a point
sceneManager.transform.GetComponent("ScriptSceneManager").AddScore();
// get rid of the bullet after it hit a target
Destroy (gameObject);
}
}
No comments:
Post a Comment