FGTE6003: Final Major Project - Timeleap Help

TutorialEnemy.cs

Description

The script attached to the non-hostile NPC during the tutorial scene.

Script

using UnityEngine; namespace Tutorial { public class TutorialEnemy : MonoBehaviour { [SerializeField] private TutorialController tutorialController; [SerializeField] private TutorialEnemyController tutorialEnemyController; [SerializeField] private bool isHostile; private Animator _enemyAnimator; private Collider _enemyCollider; private static readonly int IsDead = Animator.StringToHash("isDead"); private void Start() { _enemyAnimator = GetComponent<Animator>(); _enemyCollider = GetComponentInChildren<Collider>(); } public void Die() { if (isHostile) return; _enemyAnimator.SetBool(IsDead, true); tutorialController.EnemyChecks["Killed"] = true; tutorialController.TutorialEnemyKilled(); Destroy(_enemyCollider); } } }

Private Methods

Start()

Stores a reference to the needed components.

Public Methods

Die()

Sets the trigger on the animator to play the death animation. Updates a value on the tutorial controller to tell the script that the enemy has been killed. Calls the function on the tutorial controller to indicate the enemy has been killed, then destroys the NPC's collider.

Variables

IsDead

Hashed reference to a trigger on the animator component.

_enemyAnimator

The animator component attached to the enemy.

_enemyCollider

The collider component attached to the enemy.

isHostile

Is the enemy hostile.

tutorialController

The tutorial controller component

tutorialEnemyController

The enemy controller to be used during the tutorial.

Last modified: 30 April 2024