Hey guys, super new to unity, but I felt fairly confident in collision trigger until the last hour and half working on this one. Please tell me what I’m doing wrong!!
I have an empty mesh with a box collider marked as “Trigger” on it. I want to return the player to the Main Menu (“Main_Menu2” in my game), but he is just walking right through it! I have a rigidbody on my character. It’s happened to several different pieces of code and several meshes.
Here is my current code:
var LevelSelect : String;
function OnCollisionEnter(hit:Collision){
if(hit.collider.name == "Rat"){
Application.LoadLevel(LevelSelect);
}
}
I’ve also tried it as
...
if(hit.collider.CompareTag == "Player"){
...
Please help!!!
And i’ve done OnTriggerEnter’s…
collider.name is fine. It’s not working because the collider is marked as a trigger but you’re using OnCollisionEnter. Use OnTriggerEnter
No go…and now almost any function dependent upon the player’s interaction have stopped working as well as a few that are not dependent upon the player. I’m super confused cause I didn’t touch any of the other scripts or settings in the inspector.
Nothing…not even an error issue. I’m getting 2 NullReference Exception notices, but they are on other scripts…
just tried this on the empty GameObject:
var boxCol : GameObject;
var level : String;
function onTriggerEnter(hit : Collision){
if(hit.collider.name == "Rat"){
Application.LoadLevel(level);
Debug.Log("about damn time");
}
}
Capitalization is important, OnTriggerEnter is different from onTriggerEnter.
Thank you! Still learning. 