Hi all! I went to the Unity site to get a tutorial on the health system. I got this script for JS:
#pragma strict
public var health : float = 100f;
public var resetAfterDeathTime : float = 5f;
public var deathClip : AudioClip;
private var anim : Animator;
private var playerMovement : PlayerMovement;
private var hash : HashIDs;
private var sceneFadeInOut : SceneFadeInOut;
private var lastPlayerSighting : LastPlayerSighting;
private var timer : float;
private var playerDead : boolean;
function Awake ()
{
//Setting up the references.
anim = GetComponent(Animator);
playerMovement = GetComponent(PlayerMovement);
hash = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent(HashIDs);
sceneFadeInOut = GameObject.FindObjectWithTag(Tags.fader).GetComponent(SceneFadeInOut);
lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent(LastPlayerSighting);
}
function Update ()
{
//If health is less than or equal to 0...
if(health <= 0f)
{
//...and if the player if not yet dead...
if(!playerDead)
//...call the PlayerDying function.
PlayerDying();
else
{
//Otherwise, f the player if dead call the PlayerDead and LevelReset functions.
PlayerDead();
LevelReset();
}
}
}
function PlayerDying ()
{
//The player is now dead.
playerDead = true;
//Set the animator's dead parameter to true also.
anim.SetBool(hash.deadBool, playerDead);
//Play the dying sounds effect at the player's location.
AudioSource.PlayClipAtPoint(deathClip,transform.position);
}
function PlayerDead ()
{
//If the player is in the dying state then reset the dead parameter.
if(anim.GetCurrentAnimatorStateInfo(0).nameHash == hash.dyingState)
anim.SetBool(hash.deadBool, false);
//Disable the movement
anim.SetFloat(hash.speedFloat, 0f);
playerMovement.enabled = false;
//Reset the player sighting to turn off the alarms.
lastPlayerSighting.position = lastPlayerSighting/resetPosition;
//Stop the footsteps playing.
audio.Stop();
}
function LevelReset ()
{
//Increment the timer/
timer += time.deltaTime;
//If the timer is greater than or equal to the time before the level resets...
if(timer >= resetAfterDeathTime)
//...reset the level.
sceneFadeInOut.EndScene();
}
public function TakeDamage (amount : float)
{
//Decrement the player's health by amount.
health -= amount;
}
This came up with compilation errors:
The name PlayerMovement does not denote a valid type
The name HashIDs does not denote a valid type
the name ScreenFadeInOut does not denote a valid type
The name LastPlayerSighting does not denote a valid type
This is the link where I got it from: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn
If anyone can give me any advice or fix the script to remove the errors that would be great! I’m new to Unity and have no experience to coding other than what I’ve learned on Youtube. Thanks!