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 $$anonymous$$ · May 13, 2014 at 10:38 PM · c#multiplecheckfiring

Multifiring functions c#

I have a simple piece of code here, that should only fire once. but for some reason, it activates 'Newfirst' three times before it stops. Anyone have some insight as to why?

 if(keepchecking==0){
             keepchecking=1;
         if(CarGUI.WhichPlace==1)
             Newfirst();
         if(CarGUI.WhichPlace==2)
             Newsecond();
         if(CarGUI.WhichPlace==3)
             Newthird();
         }

(Full Script Below as requested)

 private int keepchecking = 0;
 private int mapchoice=1;
     
 private int currentfirst;
 private int currentsecond;
 private int currentthird;
     
 private string currentfirsttime;
 private string currentsecondtime;
 private string currentthirdtime;
     
 private string currentfirstuser;
 private string currentseconduser;
 private string currentthirduser;
 
     
     void Start () 
     {
         
         mapchoice = Starting.mapchoice;
         
         currentfirst=PlayerPrefs.GetInt("TimeFirst"+mapchoice);
         currentsecond=PlayerPrefs.GetInt("TimeSecond"+mapchoice);
         currentthird=PlayerPrefs.GetInt("TimeThird"+mapchoice);
         
         currentfirsttime=PlayerPrefs.GetString("FirstPlace"+mapchoice);
         currentsecondtime=PlayerPrefs.GetString("SecondPlace"+mapchoice);
         currentthirdtime=PlayerPrefs.GetString("ThirdPlace"+mapchoice);
         
         currentfirstuser=PlayerPrefs.GetString("FirstPlaceUser"+mapchoice);
         currentseconduser=PlayerPrefs.GetString("SecondPlaceUser"+mapchoice);
         currentthirduser=PlayerPrefs.GetString("ThirdPlaceUser"+mapchoice);
         
         if(keepchecking==0){
             keepchecking=1;
         if(CarGUI.WhichPlace==1)
             Newfirst();
         if(CarGUI.WhichPlace==2)
             Newsecond();
         if(CarGUI.WhichPlace==3)
             Newthird();
         }
     }
     
     void Update() {
         print (keepchecking);
         print (CarGUI.WhichPlace);
         
     }
     
     void Newfirst()
     {    
             print ("FirstFire");
             PlayerPrefs.SetInt("TimeThird"+mapchoice,currentsecond);
             PlayerPrefs.SetInt("TimeSecond"+mapchoice,currentfirst);
             PlayerPrefs.SetInt("TimeFirst"+mapchoice,CarGUI.finaltime);
         
             PlayerPrefs.SetString("ThirdPlace"+mapchoice,currentsecondtime);
             PlayerPrefs.SetString("SecondPlace"+mapchoice,currentfirsttime);
             PlayerPrefs.SetString("FirstPlace"+mapchoice,CarGUI.singlelaptime);
             
             PlayerPrefs.SetString("ThirdPlaceUser"+mapchoice,currentseconduser);
             PlayerPrefs.SetString("SecondPlaceUser"+mapchoice,currentfirstuser);
             PlayerPrefs.SetString("FirstPlaceUser"+mapchoice,OpeningScene.Username);
     }
         
     
     void Newsecond()
     {            
             print ("SecondFire");
             PlayerPrefs.SetInt("TimeThird"+mapchoice,currentsecond);
             PlayerPrefs.SetInt("TimeSecond"+mapchoice,CarGUI.finaltime);
         
             PlayerPrefs.SetString("ThirdPlace"+mapchoice,currentsecondtime);
             PlayerPrefs.SetString("SecondPlace"+mapchoice,CarGUI.singlelaptime);
         
             PlayerPrefs.SetString("ThirdPlaceUser"+mapchoice,currentfirstuser);
             PlayerPrefs.SetString("SecondPlaceUser"+mapchoice,OpeningScene.Username);
     }
         
     
     void Newthird()
     {    
             print ("ThirdFire");
             PlayerPrefs.SetInt("TimeThird"+mapchoice,CarGUI.finaltime);
             PlayerPrefs.SetString("ThirdPlace"+mapchoice,CarGUI.singlelaptime);
             PlayerPrefs.SetString("ThirdPlaceUser"+mapchoice,OpeningScene.Username);
     }
 }
Comment
Add comment · Show 17
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 ThePunisher · May 13, 2014 at 10:39 PM 0
Share

You will need to add more information in order for people to help you solve your problem.

Information needed: Where is this if check happening? What happens in the methods Newfirst, Newsecond, and Newthird.

avatar image $$anonymous$$ · May 13, 2014 at 10:48 PM 0
Share

I've added the full script, though it's mostly just boring playerpref stuff.

avatar image Pawscal · May 13, 2014 at 10:52 PM 0
Share

Is your script on multiple objects? That could explain why it runs 3 times NewFirst()

avatar image SkaredCreations · May 13, 2014 at 11:14 PM 1
Share

Well, I added this (commenting all the code inside the "New*" functions except the print debug) and tried very many times to start/stop the editor and it was never printed more than one time, so it's most likely something else in your other logic scripts. Try to add print(gameObject.name) in the Start function, comment the Update and finally look at the stack trace in your console window when you start to verify what/when are the calls co$$anonymous$$g from, there's definitely no issues in this code.

avatar image SkaredCreations · May 13, 2014 at 11:59 PM 1
Share

The stack trace shows the order of calls, so I don't know what you're seeing or interpreting.

Here is the code I'm trying (import in your project, create a blank scene and attach it to the camera or a new gameobject):

 using UnityEngine;
 using System.Collections;
 
 public class Test : $$anonymous$$onoBehaviour {
 
     private int keepchecking = 0;
 
     class CarGUI1 {
         public static int WhichPlace = 1;
     }
     
     void Start () 
     {
         
         if(keepchecking==0){
             keepchecking=1;
             if(CarGUI1.WhichPlace==1)
                 Newfirst();
             if(CarGUI1.WhichPlace==2)
                 Newsecond();
             if(CarGUI1.WhichPlace==3)
                 Newthird();
         }
     }
     
     void Newfirst()
     {  
         print ("FirstFire");
     }
     
     void Newsecond()
     {       
         print ("SecondFire");
     }
     
     void Newthird()
     {  
         print ("ThirdFire");
     }
 }


It prints "FirstFire" only once on me, see if it's the same for you, in which case there's really something else in your other scripts that is interfering. $$anonymous$$aybe you could export your demo scene with all dependencies? as I see here the only dependencies should be the scripts CarGUI, Starting and OpeningScene, it's the only way to understand what's going on else we're walking in the darkness

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Check if two objects have the same position. 2 Answers

Best practices for multiple databases 1 Answer

An OS design issue: File types associated with their appropriate programs 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