using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : Character { [SerializeField] private float attackRange; [SerializeField] private float attackRate; private float lastAttackTime; [SerializeField] private GameObject attackPrefab; public static Player Current; private Animator animator; void Awake() { Current = this; animator = GetComponentInChildren(); } void Update() { if (target != null) { float targetDistance = Vector3.Distance(transform.position, target.transform.position); if (targetDistance < attackRange) { Controller.StopMovement(); Controller.LookTowards(target.transform.position - transform.position); if (Time.time - lastAttackTime > attackRate && target.GetComponent() != null) { animator.SetTrigger("attack"); lastAttackTime = Time.time; GameObject proj = Instantiate(attackPrefab, target.transform.position + Vector3.up, Quaternion.LookRotation(target.transform.position - transform.position)); proj.GetComponent().Setup(this); proj.GetComponent().DamageTarget(target); } } else { Controller.MoveToTarget(target.transform); } } } }