- Home /
OnTrigger2D not working for me....
I am trying to make a simple code to allow the camera to move, but only when the player reaches certain bounds, so I made the main camera the child of a empty gameobject with a simple script telling it where to move when another script attached to the player tells it too. The players script is also simple and works as follows, when the player is in a box trigger collider2d attached to the empty gamebject tagged "Finish" the script will set a bool to false and change it to true when the player exits the trigger. the problem is, its not working, not one part of it is... here's the code
using UnityEngine;
using System.Collections;
public class PlayerMoveCamera : MonoBehaviour {
public bool playerOut;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//playerOut = true;
}
void OntriggerExit2D (Collider2D other)
{
if (other.gameObject.CompareTag ("Finish")) {
playerOut = true;
}
}
void OntriggerStay2D (Collider2D other)
{
if (other.gameObject.CompareTag ("Finish")) {
playerOut = false;
Debug.Log ("still in");
}
}
}
the debug isn't working, and i can see that the public bool isn't changing.... In the update function I have a line commented out that was a test, and it worked very well.
Answer by zach-r-d · Jul 15, 2015 at 05:22 AM
Ah, just capitalize the "T"s. The methods must named OnTriggerExit2D and OnTriggerStay2D; OntriggerExit2D and OntriggerStay2D will not be called.
F%!#, am I allowed to cuss? Probably not.... Thank you good sir.
Hahaha, don't worry, it's a mistake anyone who uses Unity makes at some point. Glad it's working!
Your answer
Follow this Question
Related Questions
How to get my targeting system working correctly 1 Answer
How to spawn a prefab on a trigger? 3 Answers
C# OnTriggerStay Collider Problem 1 Answer
How to run what's inside OnTriggerEnter temporarily while the two objects are in contact? 1 Answer
making position checker - is area empty or not (with trigger)? 2 Answers