Sunday, March 9, 2014

Astroid script

//Astroid script

 //Inspector variables
 var astroidSpeed : float = 15.0;
 var explosion    : Transform;
 var sceneManager : GameObject;

 //Private Variable

 // Game loop
 function Update ()
{
   transform.Translate(Vector3.down*astroidSpeed*Time.deltaTime); // vector3.down = move object down on y axis
 
  // make astriod re appear at the top when it hit the bottom
  if(transform.position.y <= -10)
  {
    // reset enermy position
    ResetEnermy();
  }
}

function OnTriggerEnter (other : Collider)
{
if(other.gameObject.tag == "Player")
{

 other.GetComponent("ScriptPlayer").lives -=1;  // get component to get component of other source

 // Tell score manager that we lost a life
sceneManager.transform.GetComponent("ScriptSceneManager").SubtractLife();
   if (explosion)
 {
  Instantiate(explosion,transform.position,transform.rotation); //explosion will be created at astriod location
 }
 // Reset enermy position
ResetEnermy();
}
if(other.gameObject.tag == "shield")
{
if(explosion)
{
Instantiate(explosion,transform.position,transform.rotation);
}
ResetEnermy();
}
}

function ResetEnermy()
{
//Reset Enermy position
transform.position.y = 15;
    transform.position.x = Random.Range(-10,10);
}

No comments:

Post a Comment