Well I’m getting completely confused over something which I’m guessing should be pretty easy. I’m trying to destroy a script on the player when the player collide’s with a box but I’ve scripted it wrong.
Here is what I have so far:
function OnTriggerEnter (Player : Collider)
{
Destroy(GetComponent("Script"));
}
Can someone please point me in the right direction?
You were close. You have to access the script from the thing that triggered the method… which is the Parameter Player… You should name it col for collision or collider… since that’s what its pulling in.
Also you should check if the player hit it… If the trigger is triggered by environment or enemy which it can it will attempt to remove the script from it and fail…
function OnTriggerEnter (col : Collider)
{
//You could add more security that this is the correct type of entity by using the Layers..
// Example Player layer is 8.. Check for the 8th layer..
if(col.gameObject.GetComponent("Script") != null col.gameObject.Layer == 8)
Destroy(col.gameObject.GetComponent("Script"));
}
Sorry I didn’t have a chance to test the script earlier and I’m still a little confused and was hoping someone could explain. What exactly does the “col” reference? Should I be naming something on the player col? Thanks in advance