- Home /
How do I trigger my animation with a cube(collider) and a triggerplatform (triggerzone)?
I have no ideer how to fix this. What I want, is my dooranimation to play (open) when my cube collider enters this squared triggerzone i have created. And yes, I have marked my triggerzone, "Is trigger". In the picture below is my animator setting for my "Platformtrigger"- animatorcontroller. I assumed that i needed a boolean parameter to make something trigger, so i have a bool called, "Play", and it's set to false. Hopefully there's a kind soul out there who would like to help me. I would really really appreciate it, since i have been stuck with this for a while.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlatformTrigger : MonoBehaviour { private Animator animator; public bool Play; public Animation DoorOpen;
void Start()
{
//DoorOpen = GetComponent<Animation> ();
animator.enabled = true;
animator.SetBool ("Play", false);
Debug.Log ("It works!");
}
void OntriggerStay(Collider Cube)
{
if (Cube.gameObject.tag == "Cube") {
animator.SetBool ("Play", true);
Debug.Log ("TriggerStay doesn't work");
//DoorOpen.Play ("DoorOpen");
//} else {
//animation.Play ("DoorOpen" = false);
}
}
}
Answer by NinjaEntertainment · Sep 20, 2017 at 04:24 PM
Hi there! I don't use animators to play animation on trigger. I play animation in a script. here is code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class YOUR SCRIPT NAME : MonoBehaviour { //dont forget to change this to your script name
public Animation anim;
void Start () {
anim = GetComponent<Animation> ();
}
// Update is called once per frame
void OnTriggerEnter(Collider other) {
if(Input.GetKeyDown(KeyCode.E))
{
anim.Play ("YOUR ANIMATION NAME");//here you place animation name :D
}
}
}
when you save the script make an cube and place it close to door. Untick Mesh renderer and set box collider to is trigger. Expand box collider if u need as well. You can also put text when you walk to trigger and it show up saying "Press E to open door " and when you press E door play animation Open or whatever...When you put script to a trigger(gameobject or cube whatever) you put animation component and put your animation onto it. and put animation on a script. Sorry for my English if you don't understand anything ask i will respond you quickly or i will make a project for you and send you via this forum :D Best Regards :D -Ninja Entertainment
Your answer

Follow this Question
Related Questions
Animation triggers are not firing 0 Answers
Troubles with "isTrigger" 2 Answers
Can't click gameobject when over another trigger? 1 Answer
Animation in unity 2 Answers
OnTriggerExit2D not working, but OnTriggerEnter2D does??? 5 Answers