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();
}
void OnCollisionEnter(Collision col)
{
if (animator.GetBool("PunchTrigger"))
{
if (col.gameObject.tag == "Boss")
{
col.gameObject.GetComponent().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.
↧