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 Dartmor · Sep 03, 2014 at 08:12 AM · guitimescore

C#: Q about creating Score system using GUItext and Time

My game is a round maze where you need to roll the ball to the center. I need three score parameters:

  1. How many times overall player succesfully rolled the ball to the center.

  2. Fastest time

  3. How many times player rolled the ball to the center,only with time less than 3 seconds, IN A ROW.

1) My code for first parameter

 public class Reset2 : MonoBehaviour {
 
     public GUIText Score; /i dragged specific GUIText object in/
     private int Point;
 
 void Start () {
         /something/
 
     }
 
 void Update () {
         
         if /something/
         {
             /reload level/
 
             Point = 1;
             Score.text="0" + Point;
 
         
         }
 
 
     }
     
 }


 

First i need, is to show in my dragged specific GUIText object, how many times player rolled the ball to the center ( "if /something/" means that player sucessfully did it ). So GUIText, that shows it and start with "0", need to +1 every time "if /something/" triggers. But i am not sure what to change in my code, because it doesn't seem to work.

2) Fastest time. I've founded "Time.timeSinceLevelLoad" , but i am not sure how it works and should i use it or not? I need the time from the start of every session ( level ), to the end ( when the ball reachs the center, the "if/something/" part), and in case if the new time is better, it must replace GUIText for fastest time with a new record.

I guess for 2) i need to start timer counting in "Void Start" part, and in "Void Update" part i need to write something like "If new time < Record, /then/ GUIText.text = new time;"

3) Using "Time.timeSinceLevelLoad" for example, i want to record how many times IN A ROW, player succesfully rolled the ball to the center with time less than 3 seconds.

i guess i need to write in "Update part" something like

if player's time < 3 seconds then somehow set GUIText.text ="1"; if player's time is again < 3 seconds then set somehow GUIText.text="2"; if player's time is AGAIN < 3 seconds then set to 3 and etc. etc.

maybe even loop it somehow with increasing number

So, any idea how to make it right?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bubzy · Sep 03, 2014 at 08:30 AM

you need a firm idea of HOW exactly the player scores, are you using collisions or are you going to track the position? without this you are just going to be focussing on too many things at once.

Unity tracks time via Time.time so you could

 //in variable declaration
 float playTime = 0f; //store start time
 float attemptTime = 0f; //store total attempt time
 int attempts = 0; // how many goes has the player had
 
 //when player starts a new attempt
 playTime = Time.time; // do not put this inside a loop or it will constantly update;
 attempts ++;
 
 //when player completes an attempt
 attemptTime = Time.time - playTime; //this will give you time elapsed from the line "playTime = Time.time"
 
 Score.text = "Attempts : "+ attempts + "  Last Time : " + attemptTime"; //just a personal gripe about using capitalised letters for the first word of a variable, it can get confusing :)
 
 //if you wanted to display the FASTEST time, you would need another variable to compare the time with and then store the lowest in a new float called 'fastestTime' or something like that.



all that being said, it really seems like you could do with brushing up a bit more on coding, might be worth trying to make a simple pong game or something first, as all the principles are there and you don't have to come up with any concepts, it would help you get a solid foundation in logic and the Unity engine, then you can move on to your own ideas.

good luck :)

Comment
Add comment · Show 2 · 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 Dartmor · Sep 03, 2014 at 08:45 AM 0
Share

i have code how player scores, as i said - the "if/something" part is exactly when player scores; so anything below "if/something" triggers every time when player succesfulle roll the ball to the center over and over

avatar image Dartmor · Sep 03, 2014 at 08:45 AM 0
Share

i have code how player scores, as i said - the "if/something/" part is exactly when player scores; so anything below "if/something/" triggers every time when player succesfully roll the ball to the center over and over

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

23 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 avatar image avatar image

Related Questions

GUITime and Score issue. 0 Answers

Using if/else statements in GUI 1 Answer

How to create a GUI like Zombieville? 1 Answer

How to create an agenda or timetable system? 1 Answer

How to call a function only once in Update 1 Answer


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