• 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 MortonPrice · Feb 11, 2019 at 02:19 PM · waitforsecondsbutton trigger eventsclicked

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

Comment
Add comment · Show 2
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 Captain_Pineapple · Feb 11, 2019 at 02:51 PM 0
Share

Do you want to make the click of a button make another button appear? Or is your problem to assign the on click function assignement to buttons from a script?

avatar image MortonPrice Captain_Pineapple · Feb 11, 2019 at 03:10 PM 0
Share

Yes, i want to click one button, and make a new button appear, but the new button to appear once its waited 10 seconds

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Captain_Pineapple · Feb 11, 2019 at 03:11 PM

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.

Comment
Add comment · 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
0

Answer by MortonPrice · Feb 11, 2019 at 03:24 PM

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 alt text


button-1-click-event.png (8.4 kB)
button2.png (9.7 kB)
Comment
Add comment · Show 6 · 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 Captain_Pineapple · Feb 11, 2019 at 03:31 PM 0
Share

Well ok that way makes things a bit more complicated. What you want to do here is add a parent transform to your second button. To this parent transform you add the script to your second button. (For which you will now think up a clever name that describes it's function please :)) Then in the start function of your script you do 2 things. First is to start the timer coroutine that you already have. Second is to find the button in the children of your script transform and deactivate it (in case it not already is) Then when the timer runs out you only have to activate the transform/gameobject of the second button in the scripts children.

If you keep button 2 and the script running its behaviour on the same transform/gameobject you will have problems when activateing/disabling said object. By keeping them a step apart this makes things easier.

avatar image MortonPrice Captain_Pineapple · Feb 11, 2019 at 03:38 PM 0
Share

Apologies i'm so lost i have no idea what a parent transform is

avatar image Captain_Pineapple MortonPrice · Feb 11, 2019 at 03:44 PM 1
Share

No worries, everyone has to start somewhere.

All objects are existent in a hierarchy. Each object in Unity is/has a transform. When you add a transform you can drag/drop it on another object in the heirarchy to make it the child of the first object. Then the upper object is the parent of the lower object and can be accessed by transform.parent from the child object.

On the other hand you can iterate over all children in a transform by calling:

     foreach(Transform t in transform)
     {
         Debug.Log("I am "+ t.name + " a child of " + transform.name);
     }

Read/do some tutorials on this. this will help you understand the unity basics.

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

100 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

Related Questions

WaitForSeconds vs yield every frame 3 Answers

yield WaitForSeconds not returning 1 Answer

Create a 10 second delay using WaitForSeconds 2 Answers

Animation there but not playing? 1 Answer

WaitForSeconds get stuck after update of Unity Pro 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges