- Home /
Action activates trigger.
Hi,i have lever in my game,everything is set....When i press lever i want on other side of map enables (turns on) Box Collider with IsTigger activated and with all scripts on it.HOW TO DO THAT? How to activate another trigger by action? Help?
Please don't write in all CAPS if you don't have to, it's basic netiquette.. also what's the point of beginning your comment with a smiley? Anyway... I think you can't trigger a trigger from code, it needs a collision. Also, it's not very good semantically, because even if you do it with some hack, well, it will be just a hack.
Ins$$anonymous$$d, get a reference to the object you want to "activate" and wrap your functionality on it to a proper method you can call. Alternatively, fire an event on collision and have the other object's script catch that event and react on it.
Answer by 2dkot · Jan 08, 2013 at 05:25 PM
You should write script which finds required game Object and then activate required component. It is quite high level description, for details check:
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.Find.html http://docs.unity3d.com/Documentation/ScriptReference/GameObject.GetComponent.html
Some like that:
using UnityEngine; using System.Collections;
public class Debuger : $$anonymous$$onoBehaviour {
GameObject targetObject;
void Start()
{
//Game Object name is "target"
targetObject = GameObject.Find("target");
}
//This method should be called after required action
void listenAction()
{
targetObject.GetComponent<BoxCollider>().isTrigger = true;
}
}
$$anonymous$$aybe you mean something like: void OnTriggerEnter(Collider other){ other.GetComponent(ScriptWithOnTriggerEnter).OnTriggerEnter() } p.s. code messed up through comment