private void FollowPlayer() { animator.SetBool("Find", true); if (player.transform.position.x < gameObject.transform.position.x && faceRight == true) { Flip(); } if (player.transform.position.x > gameObject.transform.position.x && faceRight == false) { Flip(); } headinToPlayer = gameObject.transform.position - player.transform.position; direction = headinToPlayer / distanceToPlayer; if (distanceToPlayer <= attackRange) { StopFollowPlayer(); if (chillTime <= 0f) { animator.SetBool("killing", true); Attack(); } } else { animator.SetBool("killing", false); } if (GetComponent <Enemy>().currentHealth <= 0) { gameObject.SetActive(false); HealtBar damage = player.GetComponent <HealtBar>(); damage.GiveHealth(); } }
private void Start() { currentHealth = maxHealth; GM = GameObject.Find("GameManager").GetComponent <GameManager>(); player = GetComponent <Player>(); healtBar = GameObject.FindGameObjectWithTag("HealthBar").GetComponent <HealtBar>(); healtBar.SetMaxHealth(maxHealth); }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <HealtBar>()) { HealtBar damage = other.GetComponent <HealtBar>(); damage.GiveDamage(2); } }
private void Attack() { chillTime = delay; HealtBar damage = player.GetComponent <HealtBar>(); damage.GiveDamage(1); if (damage.GetHealth() == 0) { StopFollowPlayer(); animator.SetBool("killing", false); } }
public void Awake() { //if(!Voice) // Voice = GetComponentInChildren<AudioSource>(); if (Voice) { VoicePitch = Random.Range(PitchMin, PitchMax); if (CharacterRace == Race.Zombie) { VoicePitch /= 2; } Voice.pitch = VoicePitch; } if (!HealtBar) { HealtBar = GetComponentInChildren <HealtBar>(); } for (int i = 0; i < (int)Equipment.EquipLocations.COUNT; i++) { Equipped.Add((Equipment.EquipLocations)i, null); } if (HasEquipment) { Equip(EquipmentGen.GetRandomEquipment()); } //------------------------- STAT SET-UP -------------------------- DMG = new Stat(StatType.DAMAGE, Random.Range(DamMin, DamMax)); AIM = new Stat(StatType.AIM, Random.Range(AimMin, AimMax)); COU = new Stat(StatType.COURAGE, Random.Range(CouMin, CouMax)); SPE = new Stat(StatType.SPEED, Random.Range(SpeMin, SpeMax)); SMA = new Stat(StatType.SMARTS, Random.Range(SmaMin, SmaMax)); Stats = new List <Stat>() { DMG, AIM, COU, SMA }.ToDictionary(s => s.Type); //Health is a special case HEA = new Stat(StatType.HEALTH, Random.Range(HeaMin, HeaMax)); Health = HEA.GetStatMax(); Material = GetComponentInChildren <Renderer>().material; if (Material && Material.HasProperty("_Color")) { NormalColor = Material.color; } DamageColor = Color.red; OnDamage.AddListener(x => StartCoroutine(HurtRoutine())); OnDeath.AddListener(Die); OnDeath.AddListener(c => OnAnyCharacterDeath.Invoke(c.CharacterRace)); AttackRange = transform.lossyScale.x * 2f; OnTargetDeath.AddListener(TargetGone); OnBeingAttacked.AddListener(BeingAttacked); OnCharacterCharacter.AddListener(AttackCharacter); if (!navMeshAgent) { navMeshAgent = GetComponentInChildren <NavMeshAgent>(); } //navMeshAgent.speed = SPE.GetStatMax() /2f; Set in fixedupdate Morale = COU.GetStatMax() * 2; if (!navMeshAgent) { Debug.LogWarning(name + ": character does not have Nav Mesh Agent"); } }