- Home /
Problems with script
Hi guys! I wrote script which shoul take me back to menu after player jumps on special floor. I wrote such script and the debugger is saying that the code is okay, but it doesn't work.
using UnityEngine;
using System.Collections;
public class EndGame : MonoBehaviour {
public string levelToLoad;
void OnTriggerEnter (Collision col){
if(col.gameObject.name == "KoniecGry"){
Application.LoadLevel (levelToLoad);
}
}
}
I tried everything. Main Camera is a rigidbody and has this script attached. The special floor called KoniecGry also has this script, but doesn't has the rigidbody component. I don't know where is the mistake :/
Answer by vexe · Sep 29, 2013 at 05:21 PM
OnTriggerEnter takes a Collider
as an argument, it's OnCollisionEnter that takes a Collision
:) - The way you wrote it, it's a brand new function called OnTriggerEnter
that accepts a Collision
input, no one ever calls it, there's no reason it gets executed when your objects collide.
And btw for OnTriggerEnter
to work, make sure you tick isTrigger
on one of your colliders.
Your answer
Follow this Question
Related Questions
Finishing game script c# 2 Answers
how do you actually stop a game? 3 Answers
End game then an Object is close to another object? 0 Answers
Multiplayer Script error 2 Answers
Disabling a GameObject via keyboard 2 Answers