- Home /
Question by
Octurn · Aug 07, 2015 at 06:32 AM ·
2dtriggercollider2dontriggerexitontriggerenter2d
OnTriggerEnter and Exit seem to not be working
Note this game is 2D.
I'm submitting this because I've seen similar questions with no resolution. I have a code set (see below) that when the trigger collider enters the other collider with the tag "ground" (to get the character to jump but not twice) it should change the bool's state, however, it does not do this at all, advice? (please don't shorthand any code, I don't know any code shorthand)
using UnityEngine;
using System.Collections;
public class JupmScript : MonoBehaviour {
public float thrust = 600;
public bool grounded;
// Use this for initialization
void Start () {
}
void onTriggerEnter2D (Collider2D other)
{
if (other.gameObject.tag == "ground") {
grounded = true;
}
}
void onTriggerExit2D (Collider2D other)
{
{
if (other.gameObject.tag == "ground")
{
grounded = false;
}
}
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.W) && grounded == true) {
GetComponent<Rigidbody2D>().AddForce(Vector2.up * thrust);
}
}
}
Comment
Best Answer
Answer by tanoshimi · Aug 07, 2015 at 06:32 AM
OnTriggerEnter2D not onTriggerEnter2D.
FUC$$anonymous$$ I can't believe that was it! I've written the code a hundred times before and didn't notice! Agh, well thank you very much, internet jesus