Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

GameObject Active problem!!!

Discussion in 'Scripting' started by RohailTariq, Nov 2, 2015.

  1. RohailTariq

    RohailTariq

    Joined:
    Jan 7, 2015
    Posts:
    8
    Hi guys, i wanted to ask that i have created a button from which player will get 500 coins on every 1st day of the month and when he collects his reward(500 Coins) the button will disappear. The problem lies on the start of the game that button is active every time i start the game.
    The solution i want is that i click the button on the 1st day of month and collect my reward and after that button should disappear and should appear on the next month 1st date.
     
  2. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    Rohail. Should be pretty simple.

    Just attach a script to the object that says something like:

    Code (CSharp):
    1.     using UnityEngine;
    2.     using UnityEngine.UI;
    3.  
    4.     public class TestButton : MonoBehaviour
    5.     {
    6.         bool bMonthlyAvailable = false;
    7.  
    8.         void Awake()
    9.         {
    10.             bMonthlyAvailable = SomeTest();
    11.  
    12.             gameObject.SetActive(bMonthlyAvailable);
    13.         }
    14.  
    15.         bool SomeTest()
    16.         {
    17.             // Nope
    18.             return false;
    19.         }
    20.     }
    Then just make the test return true if the month's up.
     
  3. RohailTariq

    RohailTariq

    Joined:
    Jan 7, 2015
    Posts:
    8
    Thanks a lot! It helped...