Search Unity

Killcount script: need help!

Discussion in 'Scripting' started by sethestuff, Jan 26, 2015.

  1. sethestuff

    sethestuff

    Joined:
    Jul 12, 2014
    Posts:
    3
    Hi everybody! Recently, my friend and I finished a script what would count the number of enemies that were killed in a gladiator game we were making. However, we ran into one error in the code: a dialogue appeared at the bottom of the screen saying "error CS8025: Parsing error." Could someone please help me resolve this issue? I am inexperienced with coding. I have put the code down below.

    Thanks,

    sethestuff


    Code (CSharp):
    1. var int count = 0;
    2.  
    3. function OnCollisionEnter (hit : Collision)
    4. {
    5.     if(hit.gameObject.tag == Enemy)//if the enemy hit
    6.     {
    7.         count + 1; //add +1 to counter
    8.     }
    9.     GUI.Box(new Rect(10, 120, 50, 20), "Counter:" + count);
    10. }
     
  2. gamer_boy_81

    gamer_boy_81

    Joined:
    Jun 13, 2014
    Posts:
    169
    Just change this line :

    count+1; //add +1 to counter

    to this line :

    count += 1; //add +1 to counter
     
    sethestuff and elmar1028 like this.
  3. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    GUI box component mustn't be in OnTriggerEnter. It should be in its own OnGUI function.

    Your main problem is with counter + 1.
    Replace it with counter += 1
     
    sethestuff likes this.
  4. sethestuff

    sethestuff

    Joined:
    Jul 12, 2014
    Posts:
    3
    Thanks for the help, but the error is still there. I have sent pictures to help you guys conceptualize the issue.

    image1 (1).JPG image2 (1).JPG
     
  5. Juice-Tin

    Juice-Tin

    Joined:
    Jul 22, 2012
    Posts:
    245
    var count:int = 0;

    The way you wrote it is for C#, but ^ is the proper way for javascript.

    I don't use javascript much, but if you get an error with
    GUI.Box(new Rect(10, 120, 50, 20), "Counter:" + count);

    try changing it to

    GUI.Box(Rect(10, 120, 50, 20), "Counter:" + count);

    Remmember that .js files use javascript formatting, and .cs files use C# (C sharp) formatting.
     
    gamer_boy_81 and elmar1028 like this.
  6. elmar1028

    elmar1028

    Joined:
    Nov 21, 2013
    Posts:
    2,359
    Change the bit where GUI Box is.

    Make it: "Counter: " + counter.ToString()
     
    gamer_boy_81 likes this.