On trigger exit

could anyone explain me why this code doesn’t work?
This script is basicly for a ladder.

public class LadderControll : MonoBehaviour {
public CharacterController controller;
public GameObject player;
	
void Start(){		
		player = GameObject.Find("Player"); 
		controller = player.GetComponent<CharacterController>();
	}
		
void OnTriggerEnter(Collider other){
		if (other.gameObject.name == "Player"){
			controller.slopeLimit = 95;
			}	
	}

		
void OnTriggerExit(Collider other){
	if (other.gameObject.name == "Player"){
		controller.slopeLimit = 45;
		}	
	}
}

thanks in advance!

have you thrown a couple of Debug.Logs in to make certain that other.gameObject.name is in fact reading as "Player"?

It reads well, the problem is just that OnTriggerExit returns nothing, its like it just doesn't work..

Does anyone have an answer for this? OnTriggerExit is not returning anything.

Rigidbody attached to the thing with this script on it. Collider set to isTrigger.

Just to be clear, you dropped a debug statement in each event, each event is firing and printing the debug statement and returning the tag or name you're expecting?

1 Answer

1

try

public class LadderControll : MonoBehaviour {
public CharacterController controller;
public GameObject player;
 
void OnTriggerEnter(Collider other){
       if (other.gameObject.name == player.tag){
         controller.slopeLimit = 95;
         }    
    }
  
void OnTriggerExit(Collider other){
    if (other.gameObject.name == player.tag){
       controller.slopeLimit = 45;
       } 
    }
}

That still changes nothing, the OnTriggerExit is just not returning anything..