Search Unity

hello, i have problem

Discussion in '2D' started by mr-ddys, Apr 2, 2021.

  1. mr-ddys

    mr-ddys

    Joined:
    Feb 4, 2021
    Posts:
    38
    I've just made a score for my game, and I've tried to do that when you get to a certain score you'll get to the next level, I haven't done the next step code yet but it's irrelevant at the moment. I'm having a CS0029 error, line 31. Please help me.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class scoreactive : MonoBehaviour
    8. {
    9.  
    10.     public Text MyscoreText;
    11.     private int ScoreNum;
    12.     public int ScoreTarget;
    13.    
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         ScoreNum = 0;
    19.         MyscoreText.text = "" + ScoreNum;
    20.     }
    21.  
    22.    
    23. private void OnTriggerEnter2D(Collider2D Hexegon)  
    24.     {
    25. ScoreNum += 1;
    26. MyscoreText.text = "" + ScoreNum;
    27.      }
    28.  
    29. void FixedUpdate()
    30. {
    31. if(MyscoreText.text = ScoreTarget)
    32. {
    33.  
    34. }
    35. }
    36. }
    37.  
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    you need to use == in ifs

    also you cant compare strings with ints
     
  3. rahilsha2000

    rahilsha2000

    Joined:
    May 17, 2020
    Posts:
    2
    You have used = which means you are providing value which is rising error.
    You need to use == which means you are checking if your current score if equal or not

    Use this instead ->

    if(MyScoreText.text == ScoreTarget)
    {
    // Your Code Here......
    }

    Also Checkout this Channel I will be posting more unity tutorial videos for beginners
    https://www.youtube.com/channel/UCZgDptjLIunBulmt2mkxJSw