Search Unity

My DeathCounter + Jump Scare Script is giving pointless errors

Discussion in 'Scripting' started by 420BlazeIt, Aug 27, 2014.

  1. 420BlazeIt

    420BlazeIt

    Joined:
    Aug 14, 2014
    Posts:
    102
    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 :D
    Please read the comments so you can understand my script better :)

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. //I want the player to get a jumpscare when they get their 25th death. So I made a stopDying boolean.
    4. //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.
    5. //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.
    6. //I don't know why but I get 4 errors between line 25 and 35
    7. //The errors are below the script by the way
    8.  
    9. var Hud : GUIStyle;
    10. var HudTWO : GUIStyle;
    11. var deathAmount : int;
    12.  
    13. var GUIEnabled : boolean = false;
    14. var blackScreen : GameObject;
    15. var jumpScarePic : GameObject;
    16. var jumpScareSound : AudioClip;
    17.  
    18. var stopDying : boolean = false;
    19.  
    20. function Start()
    21. {
    22.     deathAmount = 0;
    23.     jumpScarePic.SetActive(false);
    24.     blackScreen.SetActive(false);
    25. }
    26.  
    27. function OnTriggerEnter(col : Collider)
    28. {
    29.     if (col.tag == "Deadzone" && stopDying == false)
    30.     {
    31.         if (deathAmount > 24)
    32.         {
    33.             stopDying = true;
    34.             JumpScare();
    35.         }
    36.         else
    37.         {
    38.             DeadPlayer();
    39.         }
    40.     }
    41. }
    42.  
    43. function JumpScare()
    44. {
    45.     jumpScarePic.SetActive(true);
    46.     audio.PlayOneShot(jumpScareSound, 3);
    47.     yield WaitForSeconds (3);
    48.     Application.LoadLevel("GameHell");
    49. }
    50.  
    51. function DeadPlayer()
    52. {
    53.     GUIEnabled = true;
    54.     deathAmount += 1;
    55.     blackScreen.SetActive(true);
    56.     yield WaitForSeconds (2);
    57.     GUIEnabled = false;
    58.     blackScreen.SetActive(false);
    59. }
    60.  
    61. var native_width : float = 1920;
    62. var native_height : float = 1080;
    63.  
    64. function OnGUI()
    65. {
    66.     var rx : float = Screen.width / native_width;
    67.     var ry : float = Screen.height / native_height;
    68.     GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
    69.    
    70.     if(GUIEnabled)
    71.     {
    72.         GUI.Box(Rect(20,18,100,50), "Deaths: " + deathAmount, Hud);
    73.         GUI.Box(Rect(Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100),"YOU DIED", HudTWO);
    74.     }
    75. }

    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!!!
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    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 )
    Code (csharp):
    1. if ( (col.tag == "Deadzone" ) && ( ! stopDying ) )
     
  3. 420BlazeIt

    420BlazeIt

    Joined:
    Aug 14, 2014
    Posts:
    102


    I FIXED IT :D. Somehow, restarting Unity fixed the errors.
    I FIXED IT :D. Somehow, restarting Unity fixed the errors.
    I FIXED IT :D. Somehow, restarting Unity fixed the errors.