I made a script so that when the player has died 25 times he/she will get jump scared and the game will load a new level.
The script is giving me errors and I don’t see how to fix them. I see nothing wrong with this script.
Here is the script I added comments to make it easier to help me
Please read the comments so you can understand my script better
#pragma strict
//I want the player to get a jumpscare when they get their 25th death. So I made a stopDying boolean.
//As you can see further down in the script when the player enters the "Deadzone" he will die and it will do the DeadPlayer function.
//But when it is the players 25th death the jumpscare is supposed to happen with a scream audio clip at the same time and then changes level.
//I don't know why but I get 4 errors between line 25 and 35
//The errors are below the script by the way
var Hud : GUIStyle;
var HudTWO : GUIStyle;
var deathAmount : int;
var GUIEnabled : boolean = false;
var blackScreen : GameObject;
var jumpScarePic : GameObject;
var jumpScareSound : AudioClip;
var stopDying : boolean = false;
function Start()
{
deathAmount = 0;
jumpScarePic.SetActive(false);
blackScreen.SetActive(false);
}
function OnTriggerEnter(col : Collider)
{
if (col.tag == "Deadzone" && stopDying == false)
{
if (deathAmount > 24)
{
stopDying = true;
JumpScare();
}
else
{
DeadPlayer();
}
}
}
function JumpScare()
{
jumpScarePic.SetActive(true);
audio.PlayOneShot(jumpScareSound, 3);
yield WaitForSeconds (3);
Application.LoadLevel("GameHell");
}
function DeadPlayer()
{
GUIEnabled = true;
deathAmount += 1;
blackScreen.SetActive(true);
yield WaitForSeconds (2);
GUIEnabled = false;
blackScreen.SetActive(false);
}
var native_width : float = 1920;
var native_height : float = 1080;
function OnGUI()
{
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
if(GUIEnabled)
{
GUI.Box(Rect(20,18,100,50), "Deaths: " + deathAmount, Hud);
GUI.Box(Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100),"YOU DIED", HudTWO);
}
}
HERE IS THE ERRORS:
Assets/Scripts/DeathCounter.js(25,25): BCE0044: expecting ), found ‘=’.
Assets/Scripts/DeathCounter.js(25,27): BCE0043: Unexpected token: 25.
Assets/Scripts/DeathCounter.js(30,9): BCE0044: expecting }, found ‘else’.
Assets/Scripts/DeathCounter.js(35,1): BCE0044: expecting EOF, found ‘}’.
Please help me fix this. I have no idea how the error messages exist. my script looks fine to me.
Thank you!!!
Seems like the line numbers on the error codes are off, did you add the comments after you ran the script and got those errors… I don’t know javascript but I would code this differently in c# ( line 29 )
I FIXED IT . Somehow, restarting Unity fixed the errors.
I FIXED IT . Somehow, restarting Unity fixed the errors.
I FIXED IT . Somehow, restarting Unity fixed the errors.