
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnTriggerEnterEnable : MonoBehaviour {
public GameObject enableTargetObject;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
print("trigger entered");
enableTargetObject.gameObject.SetActive(true);
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
print("trigger exited");
enableTargetObject.gameObject.SetActive(false);
}
}
}
This script makes an object appear ( one that is disabled ) when another object enters the collision box, and disappear when you exit the box.
Place this script on an object with a box collider.
Drag the object that you want to appear into the Enable Target Object “None (Game Object) slot” in the inspector.
The other object needs to have these things in order to trigger the enable object:
– A box collider set to trigger ( trigger checkbox checked)
– Gameobject is tagged as “Player”
– a rigid body component



