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);
}
}
}
This script makes an object appear ( one that is disabled ) when another object enters the collision.
Place this script on an object with a box collider.
Drag the object that you want to appear into the "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"
- has a rigid body component
Place this script on an object with a box collider.
Drag the object that you want to appear into the "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"
- has a rigid body component
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.