Question by
marcojay · Jul 14, 2018 at 12:21 AM ·
colliderontriggerentersetactive
ON TRIGGER ENTER GAME OBJECT SET ACTIVE TRUE
hi i need help. i want to set a object to true or false when player enters the collider. here are my codes
public class enterexit : MonoBehaviour {
public GameObject trigger;
void Start() { trigger.SetActive(false); Debug.Log("sdafasd"); }
void OnTriggerEnter (Collider player)
{
if (player.gameObject.tag == "Player")
{
trigger.SetActive(true);
}
}
}
Comment
Answer by CrazyMonkey · Sep 18, 2019 at 07:09 PM
Hi, this is my version:
public GameObject trigger;
void Start () {
trigger.SetActive (false);
}
void OnTriggerEnter(Collider _col){
if (_col.gameObject.CompareTag ("Player")) {
trigger.SetActive (true);
}
}
If you need a Trigger exit:
void OnTriggerExit(Collider _col){
if (_col.gameObject.CompareTag ("Player")) {
trigger.SetActive (false);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612170651im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Check if collider is colliding with something,Check if a collider contains any colliding objects 0 Answers
Access variable from different class 1 Answer
Text disappear on OnTriggerExit() 1 Answer
check every frame if collider entered the another collider or not 1 Answer
How to enable a portal when reaching a certain amount of score? 0 Answers