- Home /
How to get Animator.GetBool to work as a parameter in OnCollisionEnter in Unity (c#)?
I have a small amount of coding knowledge but I can't seem to wrap my mind around why this isn't working. Here is the code: public Animator animator; public float forceApplied = 50;
 private void Start()
 {
     animator = GetComponent<Animator>();
 }
 void OnCollisionEnter(Collision col)
 {
     if (animator.GetBool("PunchTrigger"))
     {
         if (col.gameObject.tag == "Boss")
         {
             col.gameObject.GetComponent<Rigidbody>().AddRelativeForce(Vector3.back * forceApplied);
         }
     }
 }
This is attached to my players hand with a sphere collider attached. While the "PunchTrigger" animation is playing and if the hand collides with the character tagged as "Boss", it should push the object back, however, nothing happens when I play the scene. The code works fine without the animator.GetBool("PunchTrigger") and the void Start() though.
Your answer
 
 
             Follow this Question
Related Questions
Can't Set Animator Boolean Parameter C# 1 Answer
How to access animator parameters with out name/string? 0 Answers
How to access Animator parameters without names/strings? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                