- Home /
A'm I setting Up My GUI style Right?
Hello I am trying to customize my GUI text and I'm not sure wether the text in my code is in the right place. It keeps giving me errors such as-error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement. Here is my script--
using UnityEngine; using System.Collections;
public class HUDscript : MonoBehaviour {
float playerScore = 0;
// Use this for initialization
void Update () {
playerScore += Time.deltaTime;
}
public GUIStyle MyGUIstyle;
void OnGUI ()
{
GUI.Label (new Rect (Screen.width - (Screen.width * 0.5f) - 50.0f, Screen.height - Screen.height, 100.0f, 30.0f), "score: ", MyGUIstyle); + (int)(playerScore * 1));
}
}
Thanks for all your help man, really appreciate it.
Sorry bud, I re edited my comment and gave u answer, It only needed repositioning and some extra not needed stragglers like semicolons and curly braces . Anyway, should sort it for you now, check answer below . ; ) Gruffy
Well I'm making a scoring system and for every second the player is alive then the score increases by one. That part is just adding the points to the GUI text. Can I put that part elsewhere in the script?
no u dont need to put it anywhere else, you almost had it right and was a goid attempt in my eyes bud, just a small misplacement issue, my answer below in the answer slot should resolve your issue and give you what you wanted.. which I think is a label with text "score:" and then the numeric value adjacent to it. If thats right, then yeah, below answers your question.
Answer by Gruffy · Mar 28, 2014 at 02:34 AM
Hey bud, your gui code call ends before it gets to the last bit.
What is this bit...
+ (int)(playerScore * 1));}
....supposed to be doing for you after ur gui call? Is it for updating ur player score to the gui. To do that, take this code you wrote....
+ (int)(playerScore * 1));}
Remove the ;} and put the rest immediately after your label's string definition, like so...
"Score: "+ (int)(playerScore * 1)), MyGUIstyle);
That get it working for you, if thats what u were trying to get sorted at least.
thanks for reading. Take care. Gruffy
Thank you so much! You have been a huge help. :)
Hey bud, no worries, could you mark it as an answer so others with similar issues may find the solution easier in future. Take care bud, and always around, so don`t be shy any problems, just ask away on here. Gruffy
If you could do the same with the other Answer I gave you for your previous question too as the same principle applies n all that, that would be grand :) Take care bud Gruffy
Your answer
Follow this Question
Related Questions
Remove GUI.Box after a few seconds. HELP!!! please 1 Answer
GUI style causing problem 0 Answers
Is it possible to detect which GUIStyleState is used? 2 Answers
GUI custom textfield cursor rendering 2 Answers