Ahoy,
This is a problem I have been dealing with for a while but never knew how to fix.
How do I get OnTriggerEnter to work?
In this script the player object has a rigidbody attached, so it should work, but absolutely no dice. I know it’s kind of a noob question, but it’s really bothering me since I need to finish this game for the GGJ 2015. The game is 2D, if that helps.
var facingRight : boolean = true;
var facingLeft : boolean = false;
var jumped : boolean = false;
var debug : boolean = false;
var ground : Collider2D;
function Update () {
if (Input.GetKey(KeyCode.D)) {
if (facingRight) {
transform.Translate (0.1, 0, 0);
facingRight = true;
facingLeft = false;
}
if (facingLeft) {
transform.Rotate (0, 180, 0);
facingRight = true;
}
}
if (Input.GetKey(KeyCode.A)) {
if (facingLeft) {
transform.Translate (0.1, 0, 0);
facingLeft = true;
facingRight = false;
}
if (facingRight) {
transform.Rotate (0, 180, 0);
facingLeft = true;
}
}
if (Input.GetKeyDown(KeyCode.Space)) {
if (jumped == false) {
rigidbody2D.velocity = Vector2(0,6);
jumped = true;
}
}
}
function OnTriggerStay (ground) {
jumped = false;
debug = true;
}
Thanks.