How to activate a trigger in state machine when object reaches position?
So I'm currently trying to make a boss fight for my Graidus shmup like game. So far I have made the script for making the boss come onto screen. Currently there is an Object in the game called Spot, which my boss moves towards before stopping at the spot. At that point it needs to move into the next state to begin the fight.
Here is the script for my Boss intro.
public class Boss_into_0 : StateMachineBehaviour { public float speed = 3; Transform Spot; Rigidbody2D rb;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Spot = GameObject.FindGameObjectWithTag("Position").transform;
rb = animator.GetComponent<Rigidbody2D>();
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
Vector2 target = new Vector2(Spot.position.x, rb.position.y);
Vector2 newPos = Vector2.MoveTowards(rb.position, target, speed * Time.fixedDeltaTime);
rb.MovePosition(newPos);
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
}
What I need to do now is activate the trigger Intro_finished in the animator and I can't figure out how to do so in my script.
So what can I do with this script to activate the trigger once the boss has moved onto the position to start the fight? I'm really struggling to figure out the state machine and the animator so please help.
Your answer
Follow this Question
Related Questions
Animation transition problem 1 Answer
The normalized time of the next state in a transition between same states 0 Answers
Trigger the Animation #2 after Animation #1 was triggered 0 Answers
How do I show "Duration in" and "Duration out" for the transition graph in the inspector window 0 Answers
Unity Bug UnityEditor.Editorwindow Close when trying to assign an Animator condition 1 Answer