Hello. I wrote my script but got error CS0131.
Here is my code:
using UnityEngine;
using UnityEngine.UI;
public class StarNum : MonoBehaviour
{
public EndTrigger endTrigger;
public int moveTextUpByThisAmount = 1;
public void Start()
{
if (endTrigger.OnTriggerEnter() = true)
{
int moveTextUpByThisAmount = 1;
PlayerPrefs.SetInt("TextUpByThisAmount", moveTextUpByThisAmount);
}
}
public void Number()
{
int moveTextUpByThisAmount = PlayerPrefs.GetInt("TextUpByThisAmount");
}
}
Here is also the error message:
Assets\Scripts\StarNum.cs(11,13): error CS0131: The left-hand side of an assignment must be a variable, property or indexer
A single “=” means assignment. A double “==” is for comparison. You probably meant to use a double “==” on line 11.
2 Likes
You have declared three (3) different variables all called moveTextUpByThisAmount
They are ALL unrelated to each other. Two of them are local. One of them is an instance variable.
Review how to declare variables and how scope works. I suspect you only want one of these variables, the instance variable. In that case, you do not want the word int on the variables that are inside the functions.
2 Likes
Also, what exactly are you doing by checking the return code from OnTriggerEnter() in Start()?!!! This is not how Unity trigger testing works. Besides, Start only runs once when this script first comes to life.
If that OnTriggerEnter function is an actual callback from Unity, it will have a void return value, and thus you cannot compare it to true.
And in any case, you certainly would never invoke it by yourself. Unity calls it for you. You do not ask Unity “did I hit this trigger?” but rather Unity tells you “Hey, you hit this trigger”
EDIT: as I already suggested to you in another thread, your continued resistance to actually working through a normal tutorial and following the steps precisely is going to forever impair your progress. Again, good luck sir.
Ok, thank you for the help.
Ok, thank you for the help.