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 msloo37 · Feb 04, 2018 at 07:02 PM · buttonbooleanboolif statementvoid

In void bool dont changing

the boolean CPU1 should unactive the button CPU1btn, but when i click on this button CPU1 dont changes, pls help

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class ShopScene : MonoBehaviour {
 
     public Image progressbar;
 
     private int perfomance;
     private int money;
 
     private bool CPU1 = false;
     private bool CPU2 = false;
     private bool CPU3 = false;
     private bool CPU4 = false;
     private bool CPU5 = false;
     private bool CPU6 = false;
 
     private bool GPU1 = false;
     private bool GPU2 = false;
     private bool GPU3 = false;
     private bool GPU4 = false;
     private bool GPU5 = false;
     private bool GPU6 = false;
 
     public Button CPU1btn;
     public Button CPU2btn;
     public Button CPU3btn;
     public Button CPU4btn;
     public Button CPU5btn;
     public Button CPU6btn;
 
     public Button GPU1btn;
     public Button GPU2btn;
     public Button GPU3btn;
     public Button GPU4btn;
     public Button GPU5btn;
     public Button GPU6btn;
 
     public void falsekek(bool a, int b, int c)
     {
         if (c == 0) {
             if (PlayerPrefs.HasKey("CPU" + b))
             {
                 a = System.Convert.ToBoolean(PlayerPrefs.GetInt("CPU" + b));
             }
         }
         else
         {
             a = System.Convert.ToBoolean(PlayerPrefs.GetInt("GPU" + b));
         }
     }
 
     void Start () {
 
         falsekek(GPU1, 1, 1);
         falsekek(GPU2, 2, 1);
         falsekek(GPU3, 3, 1);
         falsekek(GPU4, 4, 1);
         falsekek(GPU5, 5, 1);
         falsekek(GPU6, 6, 1);
 
         falsekek(CPU1, 1, 0);
         falsekek(CPU2, 2, 0);
         falsekek(CPU3, 3, 0);
         falsekek(CPU4, 4, 0);
         falsekek(CPU5, 5, 0);
         falsekek(CPU6, 6, 0);
 
         perfomance = PlayerPrefs.GetInt("perfomance");
         money = PlayerPrefs.GetInt("money");
     }
     
     public void checkbtn(Button a,bool b)
     {
         if (b == true)
         {
             a.interactable = false;
         }
     }
 
     void Update () {
 
         checkbtn(CPU1btn, CPU1);
         checkbtn(CPU2btn, CPU2);
         checkbtn(CPU3btn, CPU3);
         checkbtn(CPU4btn, CPU4);
         checkbtn(CPU5btn, CPU5);
         checkbtn(CPU6btn, CPU6);
 
         checkbtn(GPU1btn, GPU1);
         checkbtn(GPU2btn, GPU2);
         checkbtn(GPU3btn, GPU3);
         checkbtn(GPU4btn, GPU4);
         checkbtn(GPU5btn, GPU5);
         checkbtn(GPU6btn, GPU6);
 
 
         progressbar.fillAmount = perfomance / 100;
     }
 
     public void Buy(int a, bool b,int c, int d)
     {
         if (money >= a)
         {
             money -= a;
 
             b = true;
 
             perfomance += 7;
             PlayerPrefs.SetInt("money", money);
 
             if (c == 1) {
                 PlayerPrefs.SetInt("GPU"+d,System.Convert.ToInt32(b));
             }
             if (c == 0)
             {
                 PlayerPrefs.SetInt("CPU" + d, System.Convert.ToInt32(b));
             }
 
         }
         else
         {
             if (PlayerPrefs.GetString("language") == "eng")
             {
                 AndroidNativeFunctions.ShowToast("You dont have money for this!");
             }
             else
             {
                 AndroidNativeFunctions.ShowToast("У вас нет денег для этого!");
             }
         }
     }
     
     //btn gpu
 
     public void GPUbtn1()
     {
         Buy(100,GPU1,1,1);
     }
     public void GPUbtn2()
     {
         Buy(140, GPU2, 1, 2);
     }
     public void GPUbtn3()
     {
         Buy(190, GPU3, 1, 3);
     }
     public void GPUbtn4()
     {
         Buy(250, GPU4, 1, 4);
     }
     public void GPUbtn5()
     {
         Buy(380,GPU5,1,5);
     }
     public void GPUbtn6()
     {
         Buy(470, GPU6, 1, 6);
     }
 
     //btn cpu
 
     public void CPUbtn1()
     {
         Buy(100, CPU1, 0, 1);
     }
     public void CPUbtn2()
     {
         Buy(140, CPU2, 0, 2);
     }
     public void CPUbtn3()
     {
         Buy(190, CPU3, 0, 3);
     }
     public void CPUbtn4()
     {
         Buy(250, CPU4, 0, 4);
     }
     public void CPUbtn5()
     {
         Buy(380, CPU5, 0, 5);
     }
     public void CPUbtn6()
     {
         Buy(470, CPU6, 0, 6);
     }
 }
 
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
Best Answer

Answer by Bunny83 · Feb 04, 2018 at 09:54 PM

Parameters of a method are always copied or passed by value unless the method has a ref or out parameter where the parameter would be passed by reference. So changing the value of the parameter "a" inside the method does not have any effect on the variable / value that was passed to the method. You have to declare your method like this:

 public void falsekek(ref bool a, int b, int c)
 {
     // ...

And now you have to call your method like this:

 falsekek(ref GPU1, 1, 1);

This time "a" is a reference to a variable. Changing "a" inside the method will actually change the value stored in the variable that you passed to the method.

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 msloo37 · Feb 05, 2018 at 10:30 AM 0
Share

thank you so much))

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

88 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

Related Questions

check if-statement/bool when button is pressed? 1 Answer

How to turn off/on a collider using a bool variable from another script 1 Answer

Cannot implicitly convert type `void' to `bool' 1 Answer

Toggle a bool on only one object at a time by tapping an object. 0 Answers

Boolean somehow becomes false. And an Integer zero. 0 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