The left-hand side of an assignment must be a variable, a property or an indexer
Hello i get this error and i dont understand whats i did wrong can you guys help me out?
using UnityEngine;
using System.Collections;
public class GoldPerSec : MonoBehaviour {
public UnityEngine.UI.Text gpsDisplay;
public Click click;
public ItemManager[] items;
void Awake (){
if (PlayerPrefs.HasKey ("tick")) {
GetGoldPerSec() = PlayerPrefs.GetFloat ("tick");
} else {
GetGoldPerSec() = 0;
}
}
void Start (){
StartCoroutine (AutoTick ());
}
void Update (){
gpsDisplay.text = CurrencyConverter.Instance.GetCurrencyIntoString(GetGoldPerSec(), false, true) + " gold/sec";
PlayerPrefs.SetFloat ("tick", GetGoldPerSec());
}
public float GetGoldPerSec (){
float tick = 0;
foreach (ItemManager item in items) {
tick += item.count * item.tickValue;
}
return tick;
}
public void AutoGoldPerSec (){
click.gold += GetGoldPerSec () / 10;
}
IEnumerator AutoTick (){
while(true) {
AutoGoldPerSec ();
yield return new WaitForSeconds(0.10f);
}
}
}
It gives me the The left-hand side of an assignment must be a variable, a property or an indexer Error on line 12 and 14
Answer by dudester · Oct 09, 2015 at 07:44 PM
first problem is you cant change a functions float value cause a function which in your case is float goldpersec()
is not a variable for a variable you want to say like so .
public float goldpersec;
and to set goldpersec you want to use playerprefs.getfloat , but to save it use playerprefs.setfloat . hope this helps.
on a second look at your script you are accessing a script not a function hence the error , unfortunatly i have no idea what you are trying to do so am unable to help
Im trying to save the float GetGoldPerSec on line 27 so i can auto save the game using the playerprefs. so if (PlayerPrefs.Has$$anonymous$$ey ("tick")) { GetGoldPerSec() = PlayerPrefs.GetFloat ("tick"); } else { GetGoldPerSec() = 0; }
Looks if there is a playerpref called tick and if there isnt one it sets the getgoldpersec to 0 and PlayerPrefs.SetFloat ("tick", GetGoldPerSec()); saves the float every frame
ok im going to fix my answer cause on a second look i can see you are confused .
Your answer
Follow this Question
Related Questions
Multiple .dll files missing, right after installing Unity 0 Answers
Error stage @username 1 Answer
"error CS1525: Unexpected symbol `end-of-file' " I've tried everything.... 1 Answer
My Player Character Have Infinite Jumping + ArgumentException Error 1 Answer
Unity bug gives false error messages or doesen't work without a Debug.Log() line present 1 Answer