I need help writing a script. I’m trying to make a simple script where when the player rolls onto a block, the block lights up (by creating a point light above it); and when the player rolls off the block, it returns to normal (by deleting the point light). I have the first part working but when the player rolls off the block, the block stays lit up. Also if the player rolls back onto the block it creates another point. Here is my script so far.
#pragma strict
var blockEffect : Transform;
function OnTriggerEnter (info : Collider)
{
if (info.tag == "Player")
{
Debug.Log ("Player is colliding");
var effect = Instantiate(blockEffect, transform.position, transform.rotation);
//This makes the point light
Destroy(effect.gameObject, 10);
//This destroys the point light after 10 seconds, but i want it to destroy it when the player stops colliding with the block.
Destroy(gameObject, 30);
}
}
function OnTriggerExit (info : Collider)
{
if (info.tag == "Player")
{
Debug.Log ("Player is not colliding");
}
}
Any help would be greatly appreciated! I am new to the unity community and Javascript so I apologize if this is a newbey question.
Thanks!
Micah