Heres my existing code for a missile projectile that I have. What I would like is for my missile to do is once its fired go up along the y axis (in this case straight up) for a frame or two then target the enemy. Ive implemented a coroutine but of course its wrong because now my script wont compile at all.
Now based on what I’ve been researching a coroutine would be the best way to go. I believe that I’ve placed the code in the right spot but it doesn’t work.
Can someone please point out the error for me.
Thanks
var myExplosion : GameObject;
var myTarget : Transform;
var myRange : float = 10;
var mySpeed : float = 10;
var myDamageAmount : float = 25;
private var myDist : float;
function Start ()
{
audio.Play();
}
function MissleMoveUp()
{
transform.Translate(0,Time.deltaTime, 0);
yield WaitForSeconds (waitTime);
}
function Update ()
{
transform.Translate(Vector3.forward * Time.deltaTime * mySpeed);
myDist += Time.deltaTime * mySpeed;
if(myDist >= myRange)
Explode();
if(myTarget)
{
transform.LookAt(myTarget);
}
else
{
Explode();
}
}
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.tag == “Enemy” || other.gameObject.tag == “Air Enemy”)
{
Explode();
other.gameObject.SendMessage(“TakeDamage”, myDamageAmount, SendMessageOptions.DontRequireReceiver);
}
}
function Explode()
{
Instantiate(myExplosion, transform.position, Quaternion.identity);
Destroy(gameObject);
}