Как настроить авто атаку
Есть скрипт, движения и атаки, возможно кто-то сможет подсказать как сделать так чтобы когда герой останавливается он атаковал?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody myBody;
public float moveForce = 10f;
private VariableJoystick joystick;
private PlayerAnimation anim;
void Awake()
{
myBody = GetComponent<Rigidbody>();
joystick = GameObject.FindWithTag("Joystick").GetComponent<VariableJoystick>();
anim = GetComponent<PlayerAnimation>();
GameObject.Find("Attack Button").GetComponent<Button>().onClick.AddListener(PlayerAttack);
}
void Update()
{
}
void FixedUpdate()
{
myBody.velocity = new Vector3(joystick.Horizontal * moveForce, myBody.velocity.y, joystick.Vertical * moveForce);
if(joystick.Horizontal != 0f || joystick.Vertical != 0f)
{
anim.Run(true);
transform.rotation = Quaternion.LookRotation(myBody.velocity);
}
else
{
anim.Run(false);
}
}
public void PlayerAttack()
{
anim.Attack();
}
}