- Home /
Quick GUI Script Fix
My GUI Text script has some errors in it that I can't seem to fix. Please help if you can. Here are the 3 errors:
Property or indexer UnityEngine.Time.time' cannot be assigned to (it is read only) The name
guiTime' does not exist in the current context
The name guiTime' does not exist in the current context And now for my script: public class Go : MonoBehaviour { private float initialtime; private int restSeconds; int CountSeconds; int CountMinutes; private int seconds; private int minutes; private string texttime; void Update (){ initialtime = Time.time; CountSeconds = CountSeconds + (CountMinutes + 60); guiTime = Time.time = initialtime; restSeconds = CountSeconds = guiTime; seconds = restSeconds % 60; minutes = restSeconds / 60; texttime = string.Format("(00:0):(00:1)", minutes, seconds); GetComponent<GUIText>().text = texttime; if(seconds <= 0 && minutes <= 0) { //Pause the game Time.timeScale = 0; } } }
Answer by robertbu · May 31, 2014 at 02:36 AM
Line 15, you have a '=' where you should have a '-'. The line should read:
guiTime = Time.time - initialtime;
And you don't declare 'guiTime'. Somewhere you need:
float guiTime;
Thanks a bunch it fixed the errors but now I have 1 new one. It says, Cannot implicitly convert type float' to
int'. An explicit conversion exists (are you missing a cast?). The error happens under the guiTime = Time.time - initialtime;. Where it says restSeconds = CountSeconds = guiTime;