- Home /
Trigger transition to another animation.
Hey Guys,
I'm trying to set up my animations so that when my zombie enters the trigger collider of the tower he transitions to an attack animation.
Basically, I'm trying to trigger a transition to another animation when entering a trigger. I'm very new to scripting and getting a few errors on my script. Any feedback is greatly appreciated:
using UnityEngine;
using System.Collections;
public class Strike_Tower : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if(collision.transform.tag == "Tower")
{
}
BaseLayer.Trigger = true;
}
}
Thanks,
Stef
You need to provide a more complete explanation so we can help... what errors are you getting, what is BaseLayer and where does it come from, how exactly are you trying to call the animation transition etc.
Answer by findujanvier · Jul 17, 2014 at 04:46 PM
Hope this help!
using UnityEngine;
using System.Collections;
public class Strike_Tower : MonoBehaviour
{
Animator anim;
void Start(){
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if(collision.transform.tag == "Tower")
{
anim.setTrigger("YOUR_TRIGGER_NAME_HERE");
}
}
}
}
Thanks findu... I get a couple of errors when I run your awesome script:
Assets/Strike_Tower.cs(14,20): error CS0103: The name
collision' does not exist in the current context > Assets/Strike_Tower.cs(16,30): error CS1061: Type
UnityEngine.Animator' does not contain a definition forsetTrigger' and no extension method
setTrigger' of type `UnityEngine.Animator' could be found (are you missing a using directive or an assembly reference?)
??? Thoughts?
I should also add that I'm using mecanim, and trying to use the trigger parameter to move from one animation state to another...
and thanks for the help!!!!
Stef
Click on tower gameobject > click to tag drop down > add tag > create new tag, named "tower" > then set tag to your tower
Answer by Stef · Jul 18, 2014 at 07:23 PM
Solved - Didn't have rigid body on game character... thanks all