Show new button with WaitforSeconds

Hello All

Complete Newbie here

I’m trying to add a clickevent on a button1, that will show another button2 after it has waited for 10secs

i used the unity on clicked events which was great, but i have no idea how to add a delay on the 2nd button before it appears.

Can i just write a script that delays its visibility for 10Secs and apply that script to button2?

i have added this script to the button2`enter code here

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

public class NewBehaviourScript : MonoBehaviour
{
 
    void Start()
    {
        StartCoroutine(ButtonDelay());
    }

    IEnumerator ButtonDelay()
    {
        print(Time.time);
        yield return new WaitForSeconds(10);
        print(Time.time);
        
        
    }
}

`
I would be extremely grateful is someone could point me in the right direction

Well first you need a function that is called when you click the first button.
Take a look at the Button Manual Page for this. There is a OnClick List for functions that will be called when clicking the button. Simply click the plus and add an object and a function from some script on the chosen object in there. There is also a ton of tutorials on this out there. For example this one from the Unity base tutorials.

To add a button you have 2 options:

  • add a prefab that contains a button and give your managing script a reference to this prefab.
    ( easier to scale - so adding more and more buttons dynamically)
    or
  • add a button to the ui and deactivate it on start. Then keep a reference to this second button on the first button and simply set the gameobject active when the button is clicked.
    (easier to position the button and easier to set up in general - gets messy in large projects)

Hope this helps you to start with. In case you need more information on this let me know what you don’t understand and i’ll try to help you on.

Thank you Captain
i added my events to button 1, which removes itself, and adds Button 2

On Button 2 i added a script to wait for 10 seconds, but still turns on instant 132981-button2.png