so I have this script so that when the player touches a key, it changes a variable from 0 to 1 and destroys the key. but for some reason, I can’t get unity to recognize the collision between the player and the key.
i made a script
function OnCollisionEnter (col : Collision)
{
Debug.Log("hit!");
}
and what this did was show me everything that the player was colliding with. and it worked on everything except for the object of my key (which is just a sphere)
this is my full code for what i want to happen when the player gets the key
var locklevel : int = 0;
var keyGet : AudioClip;
function OnCollisionEnter (col : Collision)
{
if(col.gameObject.name == "aKey")
{
Debug.Log("hit!");
locklevel = 1;
audio.PlayOneShot(keyGet);
Destroy(col.gameObject);
}
}
this script is attached to the first person controller prefab.
why won’t it recognize a collision with the key?
(the key is also instantiated and not placed from the beggining, if that makes a difference)