How to access a animation transition paramater bool via script
I want to access a parameter in the animation I made called Shooting which is set by default to false. I want to change it to true when the enemy is inside the player's trigger. How do I do this? Can you post the script? Sometime before i'm 70 would be nice...
Answer by williamsokol12 · Dec 13, 2016 at 07:20 AM
So I started c# a few months ago and from what I can tell this is how you do it:
using UnityEngine; using System.Collections;
public class LevelComplete : MonoBehaviour {
Animator animGoal;
int GoalHash = Animator.StringToHash("GoalDone");
// Use this for initialization
void Start () {
animGoal = GetComponent<Animator>();
}
void Update ()
{
if(blahblahblah){
animGoal.SetTrigger(GoalHash);
}
}
so you need to use Animator.stringToHash as you think you would use "GoalDone" from this example BTW you may want to use a bool for something called shooting
Answer by SoraMahiro · Dec 12, 2016 at 06:11 PM
In the API it talks about function that can be called in the Animation interface called CrossFade
and there are actually plenty of other fading and transitioning effects that can be done. I would take a look here: Animation
This being said, if you want to control it strictly by script you'll need to use that and plenty of other functions provided in Animation. Otherwise you'll have to use the animation transition in the inspector of the animation controller.
Your answer
Follow this Question
Related Questions
Best way to animate a shooting-arm on my ball (Player)? 0 Answers
PROBLEM WITH ANIM.SETBOOL NOT WORKING 0 Answers
Can I play two different animations on one button? 0 Answers
Help me to make a delay when shooting 0 Answers
Animator boolean problem 2 Answers