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 NAlex · Oct 25, 2012 at 05:31 AM · javascriptcollidertriggertimerscope

Need help with game points and trigger

Hello!

How do I make the scoring (1 second = 1 point)? I have to do so that when the player touched the trigger, time stopped and the screen shows the number of points.


Here is my script:

 private var startTime :float;
 private var textTime : String;
 var G : boolean = false;
 var S : boolean = false;
 var B : boolean = false;
 var F : boolean = false;
 var other : GameObject;
 
 function Awake() {
 
    startTime = Time.time;
 
 }
 
 function OnGUI () {
 
    var guiTime = Time.time - startTime;
 
    var minutes : int = guiTime / 60;
    var seconds : int = guiTime % 60;
 
    textTime = String.Format ("{0:00}:{1:00}", minutes, seconds); 
    GUI.Label(Rect (Screen.width/2, 0, 100, 100), textTime); 
  
    if(seconds >= 10){
        G = true;
        }
    
        if(seconds >= 30){
            G = false;
            S = true;
        }
        
            if(seconds >= 90){
                G = false;
                S = false;
                B = true;
            }
            
                if(seconds >= 100){
                    G = false;
                    S = false;
                    B = false;
                    F = true;
                }
 }
 
 function OnTriggerEnter (other : Collider) {
 
    

The Problem here

 }



Comment
Add comment · Show 1
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 Sonaten · Oct 25, 2012 at 06:54 PM 0
Share

You should really make a better 'Questions topic name' "Need help!" is really a bad name as it doesn't tell the forum anything.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Paul-Sinnett · Oct 25, 2012 at 12:49 PM

You'd need to add a score variable. If you want to add 1 point per second, add Time.deltaTime to score within function Update (). If you want to start and stop the timer, make a boolean to store when you are scoring and only add when that variable is true. Then inside the OnTriggerEnter function, set the flag to false.

Comment
Add comment · Show 1 · 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 NAlex · Oct 25, 2012 at 06:42 PM 0
Share

Thanks, I will try.

avatar image
0
Wiki

Answer by Sonaten · Oct 25, 2012 at 07:02 PM

I am not really native in Javascript, but give this a try. You simply have a control variable, in this case a bool, which controls wether or not a certain part of the code is executed. I assume that you want the calculations to stop.

Hope this can help you out.

 private var startTime :float;
 private var textTime : String;
 var G : boolean = false;
 var S : boolean = false;
 var B : boolean = false;
 var F : boolean = false;
 var other : GameObject;
 
 //Edited here. isRunning added and 3 vars moved to outer scope
 var isRunning : boolean = true;
 
 var guiTime;
 var minutes : int;
 var seconds : int;
 
 function Awake() {
 
    startTime = Time.time;
 
 }
 
 function OnGUI () {
 
     //Calculations. Stop them if trigger is hit 
     if (isRunning)
     {
        guiTime = Time.time - startTime;
        minutes = guiTime / 60;
        seconds = guiTime % 60;
        }
 
    textTime = String.Format ("{0:00}:{1:00}", minutes, seconds); 
    
    GUI.Label(Rect (Screen.width/2, 0, 100, 100), textTime); 
 
    if(seconds >= 10){
     G = true;
     }
 
        if(seconds >= 30){
            G = false;
            S = true;
        }
 
           if(seconds >= 90){
              G = false;
              S = false;
              B = true;
           }
 
             if(seconds >= 100){
               G = false;
               S = false;
               B = false;
               F = true;
             }
 }
 
 function OnTriggerEnter (other : Collider) {
     if(other.tag == "triggerObjectTag") isRunning = false;
 }
Comment
Add comment · Show 1 · 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 NAlex · Oct 28, 2012 at 12:19 AM 0
Share

Thank you! This is work.

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

10 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

Related Questions

Enable objects to enter the trigger 2 Answers

Script not responding to key press immediately. 1 Answer

Can a object without a rigidbody be triggered by a trigger? 1 Answer

Script error: OnTriggerEnter 1 Answer

Using a Single Collider to Detect Collisions with Multiple Colliders 3 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