- Home /
Activate Gui Texture On Trigger Activate
How do i activate gui texture when player enters collision (trigger)?
this is my script
var jumpscare : GameObject;
function Update () {
jumpscare.SetActiveRecursively(false);
}
function OnTriggerEnter(){
jumpscare.SetActiveRecursively(true);
}
Answer by Tomer-Barkan · Nov 01, 2013 at 05:20 PM
You're currently deactivating it in the Update(), which runs every frame, so even if you activate it when it enters the trigger, it will only remain active for one turn. Instead, you want to deactivate in the Start() once, then activate when trigger enters and deactivate again when trigger exits:
var jumpscare : GameObject;
function Start () {
jumpscare.SetActiveRecursively(false);
}
function OnTriggerEnter(other : Collider){
jumpscare.SetActiveRecursively(true);
}
function OnTriggerExit(other : Collider){
jumpscare.SetActiveRecursively(false);
}
Thank you for explanation. The problem is that trigger is not activating.
btw jumpscare : gameobject; is gui texture with animation, if it helps.
It should be triggered. Did you add the variable other : Collider
like I did? Try printing a debug log to see if it's triggered.
$$anonymous$$eep in $$anonymous$$d - in order for a collider to be triggered like this, it must be set as "isTrigger = true" (do this in the inspector or in the Start() method), and one of the objects that collide must have a rigidbody.
Watch these tutorials if you haven't yet:
http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders
http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders-as-triggers