Search Unity

(34, 12) ERROR CS0201: only assignment, call, increcement, decrecement, await, and new object expres

Discussion in 'Scripting' started by marijnkneppers, Aug 24, 2019.

  1. marijnkneppers

    marijnkneppers

    Joined:
    Aug 24, 2019
    Posts:
    3
    Can someone help me pls?
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class Score : MonoBehaviour
    7. {
    8.     public float CurrentScore = 0;
    9.     public Text ScoreText;
    10.     public Text Highscoretext;
    11.     public float Highscore;
    12.    
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         Highscoretext.text = ("Highscore: ") + PlayerPrefs.GetFloat("Highscore").ToString();
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void Update()
    21.     {
    22.         ScoreText.text = ("Score: ") + CurrentScore;
    23.  
    24.         if(PauseMenu.GameIsPaused == true)
    25.         {
    26.            
    27.         }
    28.         else
    29.         {
    30.             CurrentScore++;
    31.         }
    32.         if (Highscore <= CurrentScore)
    33.         {
    34.             Highscore == CurrentScore;
    35.  
    36.             PlayerPrefs.SetFloat("Highscore", Highscore);
    37.         }
    38.     }
    39. }
     
  2. Deleted User

    Deleted User

    Guest

    Like the error message says, your error is on line 34, character # 12. You are trying to set Highscore to CurrentScore but you are using a double equal operator (==), which is a comparison. To set a value, you need to use =, which is an assignment.
     
    Last edited by a moderator: Aug 24, 2019