I’ve gotten an attack animation working and was trying to figure out how to add knockback to the attack.
Keep in mind I don’t wish to destroy or subtract health from the enemy only knockback them back.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class armcontroller : MonoBehaviour
{
public GameObject arms;
public bool CanAttack = true;
public float AttackCooldown = 1.0f;
public AudioClip Armattacksound;
void Update()
{
if (Input.GetMouseButton(0))
{
if (CanAttack)
{
ArmAttack();
}
}
}
public void ArmAttack()
{
CanAttack = false;
Animator anim = arms.GetComponent<Animator>();
anim.SetTrigger("attack");
AudioSource ac = GetComponent<AudioSource>();
ac.PlayOneShot(Armattacksound);
StartCoroutine(ResetAttackCooldown());
IEnumerator ResetAttackCooldown()
{
yield return new WaitForSeconds(AttackCooldown);
CanAttack = true;
}
}
}