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. Dismiss Notice

"Error ; expected" but there is already a ";" in Unity 2019.4.18f1

Discussion in 'Scripting' started by kristosaber, Jan 27, 2021.

  1. kristosaber

    kristosaber

    Joined:
    Jan 20, 2021
    Posts:
    33
    Hi,

    I'm posting the post here as I post it wrongly previously.

    I'm trying to create a clicker game using the codes below. For some reason, I keep having the error prompt.

    I hope I can have some advise. Thank you.

    Unity 2019.4.18f1

    upload_2021-1-27_22-42-54.png

    In CriticalClick.cs
    Code (CSharp):
    1. using UnityEngine;
    2. public class CriticalClick : MonoBehaviour
    3. {
    4.     public GameObject PopUp;
    5.     public Animator Ani;
    6.     public void Play()
    7.     {
    8.         Ani.Play(statename: "CriticalCritEffect");
    9.         Destory(GameObject, 0.5f);
    10.     }
    11. }

    In ClickManager.cs.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class ClickManager : MonoBehaviour
    7. {
    8.     public int Clicks = 0;
    9.     public Text ClicksNumberText;
    10.     //public GameObject ClicksNumbersObject;
    11.     //public GameObject ClicksNormalTextObject;
    12.  
    13.     public CriticalClick crit;
    14.     public GameObject critSpawn;
    15.  
    16.     // Start is called before the first frame update
    17.     void Start()
    18.     {
    19.        
    20.     }
    21.  
    22.     // Update is called once per frame
    23.     void Update()
    24.     {
    25.         if (Clicks == 1)
    26.         {
    27.             ClicksNumbersObject.SetActive(true);
    28.             ClicksNormalTextObject.SetActive(true);
    29.         }
    30.         else if (Clicks > 1)
    31.         {
    32.             return;
    33.         }
    34.  
    35.         else if (Clicks == 0)
    36.         {
    37.             ClicksNumbersObject.SetActive(false);
    38.             ClicksNormalTextObject.SetActive(false);
    39.         }
    40.     }
    41.  
    42.     public void GenerateCritText()
    43.     {
    44.         var clone CriticalClick = Instantiate(crit, critSpawn.transform);
    45.         clone.play();
    46.     }
    47.  
    48.     public void ClickerClick()
    49.     {
    50.         Clicks = Clicks + 1;
    51.         ClicksNumberText.text = Clicks.ToString();
    52.         GenerateClickText();
    53.     }
    54. }
     
  2. descenderdante

    descenderdante

    Joined:
    Sep 3, 2009
    Posts:
    218
    Code (CSharp):
    1. var clone CriticalClick = Instantiate(crit, critSpawn.transform);
    Code (CSharp):
    1. var clone = Instantiate(crit, critSpawn.transform);
    You left a space in clone CriticalClick lol
     
    kristosaber likes this.
  3. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    452
    Change line 44:
    Code (csharp):
    1. var clone = Instantiate(crit, critSpawn.transform);
     
    kristosaber likes this.
  4. kristosaber

    kristosaber

    Joined:
    Jan 20, 2021
    Posts:
    33
    I checked that there is no space, what do you mean?
     
  5. kristosaber

    kristosaber

    Joined:
    Jan 20, 2021
    Posts:
    33
    Thank you!