public void Init(Transform target, CharactorHealth health) { myHealth = health; this.target = target; cameraTrans = Camera.main.transform; }
public void Create(Transform target, CharactorHealth health) { HealthUI newUI = Instantiate(healthUI, target.position, Quaternion.identity); newUI.transform.parent = transform; newUI.Init(target, health); }
public void Attack(CharactorHealth targetHealth) { if (attackCoolDown <= 0) { attackCoolDown = 1 / attackSpeed; targetHealth.TakeDamage(myHealth.Damage.GetValue()); if (OnAttack != null) { OnAttack.Invoke(); } } }
private void Update() { if (targetTrans != null) { float distance = Vector3.Distance(transform.position, targetTrans.position); if (distance <= attackRadius) { agent.SetDestination(targetTrans.position); if (distance <= agent.stoppingDistance) { CharactorHealth playerHealth = targetTrans.GetComponent <CharactorHealth>(); if (playerHealth != null) { combat.Attack(playerHealth); } LookTarget(); //transform.LookAt(targetTrans); } } } }
private void Awake() { myHealth = GetComponent <CharactorHealth>(); }