Help me with this code proplem,,Almost finish my game please help this once

hello people

the code here im trying to TurnOff an object called “Hidey” tagged as “Player”
when it enters a trigger

  • I put the script inside a box with a boxcollider set to (Is Trigger)

The Proplem is the code turns off the object before it enters the trigger ,PLS HELP

using UnityEngine;
using System.Collections;

public class worldTrigger : MonoBehaviour {

	private GameObject hidey;
	void Start() {
		hidey = GameObject.Find("hidey");
		hidey.gameObject.SetActive(false); 
	}
	void OnTriggerEnter (Collider other) {
		if (other.CompareTag ("Player")) {
			hidey.gameObject.SetActive(true); 
		}
	}
}

Almost all is fine, but your problem is that you are putting, true and false in wrong places.

Example:

  void Start() {
     hidey = GameObject.Find("hidey");
     hidey.gameObject.SetActive(false); //This need to be true
 }

  void OnTriggerEnter (Collider other) {
     if (other.CompareTag ("Player")) {
         hidey.gameObject.SetActive(true);  //This need to be false
     }

@MTDues First… your code its flipped and needs to be as @Reynards said… second you need to make sure the collider you are using to detect the collision is set to “isTrigger” in the inspector window of the collider! It needs to be check marked or else the collider system ignores it!

Your script is also wrong because you want to dissapear hidey when it hits something with the tag “player” so instead you need to put the tag of the objects that are goin to hide hidey, in this example we will use the tag “ObjectsForHidding” any collider with this tag will make it him or her disapear.

using UnityEngine;
  using System.Collections;
  
  public class worldTrigger : MonoBehaviour {
  
      private GameObject hidey;
      void Start() {
          hidey = GameObject.Find("hidey");
          hidey.gameObject.SetActive(true); 
      }
      void OnTriggerEnter (Collider other) {
          if (other.CompareTag ("ObjectsForHidding")) {
              hidey.gameObject.SetActive(false); 
          }
      }
  }

The Problem is the code turns off the object before it enters the trigger

That’s because you’ve written this in Start():

hidey.gameObject.SetActive(false); 

this script is so “Paradox” as it never does what it should do no matter how it might look well coded i almost give up on my game cuz this code

my game dependes on it greatly i need all the world energy xDDDD

The Problem is the code turns off the object before it enters the trigger

That’s because you’ve written this in Start():

hidey.gameObject.SetActive(false);