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:
using UnityEngine;
using System.Collections;
public class Trigger : MonoBehaviour {
public GameObject obj;
// Update is called once per frame
void OnTriggerEnter2D() {
obj.SetActive (true);
}
}
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)