Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can you fix my level up system?

Discussion in 'Scripting' started by Findev, Dec 22, 2015.

  1. Findev

    Findev

    Joined:
    Apr 17, 2015
    Posts:
    34
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LevelUp : MonoBehaviour {
    5. int LevelyUp = 0
    6.     void OnClick(gameObject) {
    7.         int LevelyUp = +1
    8.     }
    9. }
    Help!
    I am only a beginner developer. I only know a bit of C#. I want the int LevelyUp when someone clicks a GameObject to increase by 1.

    And there are some errors:

    Assets/LevelUp.cs(6,12): error CS1519: Unexpected symbol `void' in class, struct, or interface member declaration

    Assets/LevelUp.cs(6,22): error CS1041: Identifier expected

    Assets/LevelUp.cs(8,9): error CS1525: Unexpected symbol `}', expecting `)', `,', or `;'

    Assets/LevelUp.cs(9,1): error CS8025: Parsing error
     
  2. Mich_9

    Mich_9

    Joined:
    Oct 22, 2014
    Posts:
    118
    You are declaring a new variable LevelyUp every time the function OnClick is called
    Replace
    Code (CSharp):
    1. int LevelyUp = +1
    With
    Code (CSharp):
    1. LevelyUp++;
    Also your code is missing semicolons everywhere, that is why you get those errors. At the end of a line always put ;.
     
  3. Mich_9

    Mich_9

    Joined:
    Oct 22, 2014
    Posts:
    118
    Complete fixed code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class LevelUp : MonoBehaviour {
    4. int LevelyUp = 0;
    5.     void OnClick(GameObject a) {
    6.         LevelyUp++;
    7.     }
    8. }
    How much beginner are you?
    I'm also assuming you are calling OnClick from elsewhere, but I doubt it.
     
  4. SteveJ

    SteveJ

    Joined:
    Mar 26, 2010
    Posts:
    3,066
    Ryiah likes this.
  5. Findev

    Findev

    Joined:
    Apr 17, 2015
    Posts:
    34
  6. Findev

    Findev

    Joined:
    Apr 17, 2015
    Posts:
    34
    I'm also mostly beginner. I know some script things, like int and void, etc.