Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9090569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:24:10+00:00 2026-06-16T22:24:10+00:00

I’m developing a game in Unity using C#. A part of the code, using

  • 0

I’m developing a game in Unity using C#. A part of the code, using a boolean, decides if the player is allowed to buy an upgrade for a building or not. If he is, the integer of the building is increased by 1. Next to that, the boolean gets set to false. If he isn’t, nothing happens at the moment.

There is a button in game, functionally increasing the week number by 1, allowing the player again to be able to upgrade building (thus setting the boolean true again).

The problem is that after buying the upgrade, the boolean is set to false, and even when I set it back to true again, when I try to upgrade the building, the boolean appears to be false. I also tried to check it with the help of an integer instead of a boolean (using the values 0 and 1), but the problem is still here.

Here is some code:

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

public class ActivateTrigger : MonoBehaviour
{
    public int transtech = 0;
    public int factech = 0;
    public bool facmag = true;
    public bool transmag = true;

    void OnGUI () {GUI.Box(new Rect(0, Screen.height - 120 - 60, 150, 30), "Week: " + week.ToString());
    if (GUI.Button(new Rect(0, Screen.height - 120 - 30, 150, 20), "Continue one week"))
    {       
        NextProcess();
    }
    if (GUI.Button(new Rect(20, 70, 120, 20), "Koop upgrade") )
    {
            Debug.Log("Facmag: " + facmag);
        if (facmag == true)
            {
        facmag = false;
            }
    }

    void NextProcess()
    {
        Debug.Log("Next process called");
        facmag = true;
        transmag = true;
        Debug.Log("Facmag: " + facmag);
    }
}

So, when NextProcess() is called, the Debug Log shows the value being true. But after the first time buying the upgrade, no matter if I pressed the button to execute NextProcess() or not, the value stays false. I’m wondering if I missed something completely or not. No other code in this class uses the booleans, nor do any of the few other classes I’ve got do. So where lies the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:24:12+00:00Added an answer on June 16, 2026 at 10:24 pm

    [Short Answer]

    If your script is attached to more than 1 object only the top most button in OnGUI() is modifying facmag or calling NextProcess().

    [Slight Expansion of my comment above]

    Unity’s order of execution for scripts shared between objects is not controllable. (You can modify script order in a single object though.) That means OnGUI() will be called N times for the N objects it’s attached to, in random order. Only the “top most” GUI element at a particular mouse position will accept mouse input.

    Example:

    using UnityEngine;
    using System.Collections;
    
    public class OverlapButton : MonoBehaviour {
        public string id_;
        void OnGUI(){
                if(GUI.Button(new Rect(0,0,50,50),"Touch")){
                        Debug.Log("I'm object " + id_);
                }
        }
    }
    

    If you attach this script to 50 objects, Unity will draw 50 buttons but only 1 button will respond to a mouse click and you can’t control which one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.