Since I am new to the Unity engine, I apologise in advance for the noob question.
function OnCollisionEnter(collision:Collision)
{
if( collision.gameObject.tag == "Player" )
{
Application.LoadLevel(0);
}
}
This code was meant to mean that when the Player collides with the gameObject, that I placed the script inside, the game would load up Level 0 (In this case the Main Menu).
However, it isn’t working and I would really appreciate any help. Thanks in advance.
what means "is not working" ;) Nothing happens? The object you placed the script on needs an attached collider that is not set to isTrigger and the player needs to be tagged as Player (you can see this in the inspector while having the player selected).
– InfiniBuzzThanks for replying so quickly. I tried your solution but it didn't seem to work either. The capsule just collides with me it does nothing. Got any more ideas on how to fix this? Thanks
– SilverHorrorDevhow do you control your player? The player needs a collider as well. Are the objects rigidbodies? Try to make a debug log to see if somethings wrong with the tag. function OnCollisionEnter (col : Collision) { Debug.Log("Im working and colliding with "+col.gameObject.name); } this may spam your console ;)
– InfiniBuzzMy Player is controlled by a Character Controller (same as the enemy) neither of them have a RigidBody component in them and I used the DebugLog but nothing came up in the console that suggested that they were colliding with anything. I experimented by adding RigidBodies to both and BoxColliders but nothing seemed to work. Any more ideas?
– SilverHorrorDev