Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by PsychQ · Sep 07, 2016 at 12:49 PM · guitimercondition

FPS Styled Timer Game: Script for starting a timer on play and stopping the timer when win condition achieved.

I have a basic FPS game where I have targets all over the level with the same tag so that I can use:

if (GameObject.FindWithTag("Target") == null) { //Stop timer on GUI and print "All targets were destroyed, you win!" // Press X to Quit or Spacebar to Restart

I'm fairly inexperienced with coding, so I don't know how to start a timer on game start or make it update in real time on the GUI. I also don't know how to implement the "Press X to Quit or Spacebar to Restart." Neither on the GUI or the actual functions.

All other game mechanics are functional, so the targets destroy when shot twice etc.

If anyone has experience in this field who can help me script in C# your help would be most appreciated!

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 FirePlantGames · Sep 09, 2016 at 02:09 AM

Don't ask people to write you code.

 public Text timerUIText;
 public float currentTime;
 
 void Update ()
 {
     currentTime += Time.deltaTime;
     
     if (GameObject.FindWithTag("Target") == null) 
     { 
         timerUIText.text = "All targets were destroyed, you win! \nPress X to Quit, or Spacebar to Restart";
     }
     else
     {
         timerUIText.text = "Time: " + currentTime;
     }
 }

But I'll write it for you this time. Remember to include the UnityEngine.UI; namespace in your script. (Add this to the top of your script) using UnityEngine.UI;

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

¿ How can I do a countdown timer showed in GUI that restarts in each scene ? 0 Answers

How to make a timer that freezes the game after you hit resume 0 Answers

Having trouble moving a UI panel 1 Answer

[GUI] Conditional Trigger for Button is flawed 0 Answers

converting timer countdown to only show minute and seconds 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