- Home /
Need help with some OnTrigger Scripting
I am currently working on a maze type game, and I have run into a problem that requires some scripting that I don't know how to do. My idea is that once the player has collided with the collider, a separate game object's animation is played in which it comes down and blocks the exit of the maze. I've done some OnTrigger scripting for stuff like teleporters before, but this one has got me confused.
Answer by Auggie · Mar 26, 2013 at 03:55 AM
what if you try something like this:
make two separate scripts-
//attach this on the player gameObject
function OnCollisionEnter ( collision : Collision ){
collision.gameObject.SendMessage("PlayAnimation", SendMessageOptions.DontRequireReceiver);
}
and make another for the object in the maze
//attach this to a maze object
function PlayAnimation()
{
gameObject.animation.Play("ClosingDoorAnimation");
}
you can have the PlayAnimation() function on all of your maze object and just change the animation name inside that function.
i hope this helps...
So I attached the first script to my character controller and 2nd to the collider that's supposed to trigger the animation of the door co$$anonymous$$g down, but nothing happened. I tried to mess around with the two scripts, but got no luck. $$anonymous$$gestions? Thanks!
Answer by Chronos-L · Mar 27, 2013 at 04:09 AM
If you are looking for something similar to a trap trigger:
public class RemoteTrapTrigger : MonoBehaviour {
public GameObject trap;
void OnTriggerEnter( Collider other ) {
if( other.gameObject.CompareTag("Player") ) {
trap.animation.Play("Activate");
}
}
}
Attach this script to the trigger, assign the door/trap as the trap.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Trying to simply play this animation... Help please. 1 Answer
Animation Script Help 0 Answers
Reloading Help 2 Answers
My player won't jump? 1 Answer