Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by itkeepshappening · Mar 28, 2014 at 02:27 AM · guiguistylegui.label

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));
 }

}

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image itkeepshappening · Mar 28, 2014 at 02:39 AM 0
Share

Thanks for all your help man, really appreciate it.

avatar image Gruffy · Mar 28, 2014 at 02:54 AM 0
Share

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

avatar image itkeepshappening · Mar 28, 2014 at 02:57 AM 0
Share

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?

avatar image Gruffy · Mar 28, 2014 at 03:13 AM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image itkeepshappening · Mar 28, 2014 at 03:17 AM 0
Share

Thank you so much! You have been a huge help. :)

avatar image Gruffy · Mar 28, 2014 at 10:50 AM 0
Share

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

avatar image Gruffy · Mar 28, 2014 at 10:52 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Styling an individual button in SelectionGrid 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges