using System.Collections; using System.Collections.Generic; using UnityEngine; public abstract class BaseCharacter : MonoBehaviour { // speed at which character should move [SerializeField] protected float speed = 1.0f; // used to make character move at faster speed when running [SerializeField] protected float runSpeedMultiplier = 2.0f; [SerializeField] protected DeathTypes deathType; [SerializeField] /// /// Indicates if character is non-combat (not fighting) /// protected bool nonCombatMode; // Indicates the attack range of the current weapon selected protected float attackRange; [SerializeField] protected string weaponTag = "Weapon"; // used to cache the animator component attached to this character protected Animator animator; protected Health health; protected Weapon currentWeapon; // Start is called before the first frame update // TODO: Make Start protected and virtual, so that inherited classes can override and add to/replace Start logic protected virtual void Start() { // Get and cache the animator component of the game object this script is attached to animator = GetComponent(); health = GetComponent(); } // Update is called once per frame void Update() { } // TODO: Create abstract IsAttacking method for inherited classes to override protected abstract bool IsAttacking(); // Attack method protected void Attack() { if (animator != null) { animator.SetTrigger("Use"); animator.SetBool("Idling", true); } } // Move method protected void Move(Vector3 movement) { if (animator == null) return; if (movement == Vector3.zero) { animator.SetBool("Idling", true); } else { animator.SetBool("Idling", false); } } // Set NonCombat method protected void Die() { // TODO // Convert the current death type to an integer - see https://www.google.com/search?q=c%23+enum+to+int // Call the animator's set integer and set "Death" parameter to the converted integer death type } protected void Hurt(float damage) { // TODO // Check the damage. If damage is greater than zero // Call the animator's set trigger "Pain" // Reduce health by damage } protected void SetNonCombat(bool isNonCombat) { nonCombatMode = isNonCombat; if (animator) animator.SetBool("NonCombat", nonCombatMode); } private void OnTriggerEnter(Collider other) { // Check the tag of the collider if (other.tag == weaponTag) { // Get the weapon controller attached to the collider WeaponController weaponController = other.GetComponent(); // Hurt by the weapon's damage. if (weaponController != null) { Hurt(weaponController.Weapon.DamageAmount); } } } }