Question by
YoraeRasante · Jun 21, 2016 at 02:17 AM ·
triggerexitalternative
OnTriggerExit2D activating when Collider2D is still partially inside.
Trying to make a ladder. Most of it seems to be working, but I cannot make the player exit it properly. It is because OnTriggerExit seems to activate as soon as just a bit of the player's collider gets out of the trigger, instead of when the player is completelly outside. Couldn't find the command to check if player is inside, so... if anyone knows...
using UnityEngine;
using System.Collections;
public class Ladder : MonoBehaviour {
private Tom2DUserControl tom;
Vector3 positionLadder;
float middleLadder;
bool onladder;
// Use this for initialization
public void Start () {
tom = FindObjectOfType<Tom2DUserControl> ();
}
public void OnTriggerStay2D (Collider2D other)
{
if (other.tag == "Player") {
onladder = true;
}
}
public void OnTriggerExit2D (Collider2D other)
{
if (other.tag == "Player") {
onladder = false;
}
}
public void Update()
{
if (onladder) {
tom.onLadder = true;
positionLadder = this.transform.position;
middleLadder = positionLadder.x;
tom.climbPos = middleLadder;
}
else {
tom.onLadder = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Need help with OnTriggerExit2D 0 Answers
Script for making instance of object delete itself is not doing anything. 0 Answers
Reset GameObject with trigger on respawn 1 Answer
How to activate command on all scripts 1 Answer
Help with a door slam trap 0 Answers