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 /
avatar image
0
Question by Drachnyen · Mar 03, 2019 at 07:11 PM · variableinvokerepeating

Variable bug???

// my variable named NumberOfButtons print 1 + 1 + 1 every 2 seconds due to my invokerepeating but when I clic on one of my circles it does not do a - 1 on the variable it keeps going + 1 + 1 + 1 + 1 when it should do + 1 -1 + 1 + 1 + 1

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class TheGame : MonoBehaviour { public Texture2D NormalCursor; public Vector2 hotspot = Vector2.zero; public CursorMode cursormode = CursorMode.Auto; public float GameBegin = 0; public GameObject Button; public float NumberOfButtons = 0; //buttons are the dot the player will have to clic public float Spawning = 0; public float Spawnn = 0;

 private void Start()
 {
     Cursor.SetCursor(NormalCursor, hotspot, cursormode);
 }

 void Update()
 {
     if (GameBegin == 0)
     {
         NumberOfButtons = 0;
         Spawnn = 0;
         if (Input.GetKeyDown(KeyCode.E))
         {
             Spawning = 1;
             Spawnn = 1;
             if (Spawning == 1)
             {
                 InvokeRepeating("Spawn", 2.0f, 2.0f);
                 Spawnn = 1;
             }
             print("A New Game Has Begun");
             GameBegin = 1;
         }
     }

     if (GameBegin == 1)
     {
         if (NumberOfButtons >= 7)
         {
             Spawning = 0;
             print("GameOver");
             GameBegin = 0;
             //var ButtonClone = GameObject.Find("Button (Player)(Clone)"); //repair
             //Destroy(ButtonClone); // repair
             print("Game Has Restarted" + " " + "Press E To Continue");
         }
     }
 }

 void Spawn()
 {
     if (Spawnn == 1)
     {
         var position1 = new Vector3(Random.Range(-8.30f, 8.30f), Random.Range(-3.50f, 3.50f), 0f);
         Instantiate(Button, position1, Quaternion.identity);
         NumberOfButtons = NumberOfButtons + 1;
         print(NumberOfButtons); //for testing purpose
     }
 }

 void OnMouseUp()
 {
     NumberOfButtons = NumberOfButtons - 1;
     print(NumberOfButtons);
     Destroy(this.gameObject);
 }

}

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 xxmariofer · Mar 03, 2019 at 08:06 PM 0
Share

is this script attached to the ciercle you are clicking? or where is attached to?

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

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

Related Questions

[closed] problem with invokerepeating and public variable 1 Answer

Global Variables Refuse to Cooperate 1 Answer

Variable disappears in playmode? 1 Answer

Find Object with variable, not a name. 1 Answer

Can I make variables visible to other scripts without making them visible in the Inspector? 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