Skip to content
Snippets Groups Projects
Enemy.cs 1016 B
Newer Older
  • Learn to ignore specific revisions
  • using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public abstract class Enemy : Fighter
    {
    
        [SerializeField, Tooltip("How close the AntiPlayer has to be in order for this Bandit to start attacking")]
        protected float playerDistanceToAttack = 1.25f;
    
        protected GameObject antiPlayer;
    
        protected override void Awake()
        {
            base.Awake();
            antiPlayer = GameObject.FindGameObjectWithTag("AntiPlayer");
        }
    
        protected override void Update()
        {
            base.Update();
            // Always face the AntiPlayer
            spriteRenderer.flipX = transform.position.x < antiPlayer.transform.position.x;
        }
    
        protected override bool CanAttack()
        {
            return GetDistanceToAntiPlayer() < playerDistanceToAttack;
        }
    
        protected override void Attack()
        {
            animator.SetTrigger("Attack");
        }
    
        protected float GetDistanceToAntiPlayer()
        {
            return Vector3.Distance(transform.position, antiPlayer.transform.position);
        }
    
    }