using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : Character { [SerializeField] private float attackRange; [SerializeField] private float attackRate; private float lastAttackTime; private int experience; //[SerializeField] private GameObject attackPrefab; public static Player Current; //private Animator animator; void Awake() { Current = this; animator = GetComponentInChildren(); HealthBarUI.instance.UpdateInfoPanel(experience, this.Level, this.Damage, this.MaxHp); } 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) { lastAttackTime = Time.time; Attack(target); /*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); } } } public void GainExperience(int experienceToGain) { experienceToGain += experience; int experienceToNextLevel = this.Level * 100; // Example formula for leveling up if (experienceToGain >= experienceToNextLevel) { LevelUp(); } Debug.Log("Gained " + experienceToGain + " experience."); HealthBarUI.instance.UpdateInfoPanel(experience, this.Level, this.Damage, this.MaxHp); } private void LevelUp() { Level++; MaxHp += 10; // Increase max health Damage += 2; // Increase damage CurHp = MaxHp; // Restore health on level up HealthBarUI.instance.UpdateInfoPanel(experience, this.Level, this.Damage, this.MaxHp); Debug.Log("Leveled up to " + Level + "!"); } }