- Home /
Cant change bool parameter in animator in a script
My bool wont change, I want to have an attacking animation, tha attacking animation will start by my bool Angrep gets true, but nothing happens when I press Mouse0.. Here is the script and a picture of my animator... using UnityEngine; using System.Collections;
public class PlayerAttack : MonoBehaviour { // PlayerMovement plMovement; PlayerInput plInput; Animator anim;
public float comboRate = 0.5f;
WaitForSeconds comboR;
public GameObject damageCollider;
// Use this for initialization
void Start () {
plInput = GetComponent<PlayerInput>();
anim = GetComponent<Animator>();
comboR = new WaitForSeconds(comboRate);
damageCollider.SetActive(false);
}
// Update is called once per frame
void FixedUpdate () {
if(plInput.fire1)
{
anim.SetBool("isAttacking", true);
// plMovement.canMove = false;
StartCoroutine("CloseAttack");
}
}
IEnumerator CloseAttack()
{
yield return comboR;
anim.SetBool("isAttacking", false);
}
public void OpenDamageCollider()
{
damageCollider.SetActive(true);
}
public void CloseDamageCollider()
{
damageCollider.SetActive(false);
}
}
I'm pretty sure
yeild return comboR
is not doing what you expect it to be doing.
Do you mean
yield WaitForSeconds(comboR);
It is unfinished... I had this from a tutorial and now I see I only took out half of that unneccesary part
Answer by Invertex · Jun 24, 2016 at 10:39 PM
You're setting the bool "isAttacking", which doesn't appear to exist on the Animator. It should be: anim.SetBool("Angrep", true);
I tried but it didint work so I took out the Enumorator and changed the $$anonymous$$eyCode and now It works except it dont set the boolean false again... I will test out more... Thank you very much, it helped me indirectly
I took in the Enumerator and now it dont work, do you see the error in that?
In CloseAttack() you should use WaitForSeconds(comboRate);.
Also, you need some conditionals in there to prevent the coroutine from being executed again while it's already running. I would suggest also doing your Play attack, Wait For Seconds, Stop Attack within that coroutine. Have it start the attack, then it waits for the duration in your float variable, and then stops the animation.
Good to hear. Don't forget to mark this as answered btw!
Answer by cstlmode · Jun 25, 2016 at 06:00 AM
try this var Attack : boolean =false; fonction update (){
if(!attack){ Attack =true; anim.SetBool("isAttacking", true); }
}
Your answer
Follow this Question
Related Questions
Set boolean to false when animation changes? 1 Answer
Can't Set Animator Boolean Parameter C# 1 Answer
Animations not Transitioning 0 Answers
Animation doesn't play 1 Answer
Multiple Cars not working 1 Answer