I am making a game where I want my scene named “GameScene” to restart when “Frog” (First Person Controller) hits “Water”. I am getting many errors and yes, I have the scene built. What can I do to fix this? What rigidbody’s or colliders do I add to the Frog or Water?
This is my code:
function Start () {
}
function Update () {
}
function OnCollisionEnter (collision : Collision)
{
if(collision.gameObject.tag == "Enemy")
{
Application.LoadLevel("GameScene");
}
}
If you are using Unity Physics for collisions, then you can do these :
Put a Collider and a Rigid Body component on the frog.
Put a Collider and a Rigid Body component on the water.
After you do this, you can print a Debug.Log to see if OnCollisionEnter() is called.
If its called, then there is definitely something wrong with the if() clause.
Since you are seeing the debug.log outside of the if, the collision reporting seems to be working. Have you set the Tag at the top of the inspector on your frog and on your water to “Enemy”? Not knowing how you have the game objects setup, I could only guess which one should have the tag set, but setting both should get you through the “if”.
Well, the debug doesnt work inside the function OnCollisionEnter, I thought that you meant under Function Start. I don’t think the function works at all. Does it need to be a OnTriggerEnter because its a character controller? I dont know what is happening.
Ok, yes, you need to use OnTriggerEnter because your colliders have IsTrigger checked. See if you can get a debug.log to fire in that, and if not, post your latest code with OnTriggerEnter.
Only thing I see wrong there is that you should check other.gameobject.tag == “Enemy”. I assume you are not seeing “Zone entered” in the output log?
If not, I think I would need to see if you could zip up the project and upload it so I can see if i can figure anything out by poking around in the project.