I'm starting to make a game and I can't seem to get any triggers to work. What I've tried doing is once my player passes through a wall an object in the room becomes visible. I have set up the wall with a 2D Box Collider and have applied a rigid body on my player. My script is as follows: Code (CSharp): using UnityEngine; using System.Collections; public class Trigger : MonoBehaviour { public GameObject obj; // Update is called once per frame void OnTriggerEnter2D() { obj.SetActive (true); } } Any help would be greatly appreciated!
Make sure your player also has a collider2D object and make sure either the player's collider or the wall collider have the isTrigger box checked. Jay
What is your Trigger script attached to? Also, throw a Debug.Log("Triggered!"); into the OnTriggerEnter2D() function -- that way you'll know whether the problem is with the triggering or with the obj being set to active. (If the message shows, the trigger works.) Jay PS - I would imagine Unity would throw an error if it cares, but you might want to include the parameter that's passed into the OnTriggerEnter2D function: void OnTriggerEnter2D(Collider2D other)