- Home /
 
Enable objects to enter the trigger
Hello how are you? , the map of my game this very large with many details and this giving lag, so I tried do this script that activates objects when entering a trigger, more did not work alguem can help me?
 var Cena: GameObject;
 function OnTriggerEnter(otherObj: Collider){
     if (otherObj.tag == "Player"){
         Cena.SetActive.active = true ;
     } 
     else {
         Cena.SetActive.active = false ;
     }
 }
 
              What have you tried until now ?
Do your objects have a collision box ? (one object with the trigger mode activated, the other object with a rigid body)
Are you sure you enter the trigger ? (Debug.Log to test for example)
Answer by FirePlantGames · Jun 06, 2015 at 02:55 AM
Correct me if I'm wrong, but isn't GameObject.SetActive supposed to be like this
 GameObject.SetActive(true);
 
               ???
Answer by Gardes · Jun 06, 2015 at 03:19 AM
Try this:
  var Cena: GameObject;
  function OnTriggerEnter(otherObj: Collider){
      Debug.log("triggered"); // trigger works finally
      if (otherObj.tag == "Player"){
          Debug.log("Cena enabled"); // Cena got enabled, yay \o/
          Cena.SetActive(true);
      } 
      else {
          Debug.log("Cena disabled"); // Just to check it's not instantly disabled again
          Cena.SetActive(false);
      }
  }
 
               Finally I don't know your scene, but if you got a big trigger platform for example, OnTriggerStay would be come in handy.
Your answer
 
             Follow this Question
Related Questions
Need some help an object collider that stops a timer then displays it on another scene 1 Answer
Triggers? How do I use them to finish a game? 1 Answer
Collider not working... 0 Answers
OnTriggerEnter Does Not Recognize Collider That Is Moved By iTween 0 Answers
Need help with game points and trigger 2 Answers