Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
avatar image
0
Question by d076696 · Jul 28, 2020 at 08:02 AM · button trigger eventsonclickunity remote

Event System, OnClick function

Hi, I'va a problem to change scene upon clicking the button. I use countdown so when user click all the button before the timer end, it will pop out congrats message. And if the timer end before doing so, 'game over' message will pop out. By the way, I'm new to Unity. Hope you guys can help me to sort it out. Thanks in advance.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 
 public class StartDown : MonoBehaviour
 {
     int countDownStartValue = 20;
     public Text timerUI;
     public GameObject gameOver;
     public GameObject Menu;
     public GameObject ViewCreature;
     public GameObject Exit;
     public GameObject wonM;
 
     public bool won = false;
     public Button Trash1;
     public Button Trash2;
     public Button Trash3;
     public Button Trash4;
 
 
     void Start()
     {
         countDownTimer();
         gameOver.SetActive(false);
         Menu.SetActive(false);
         ViewCreature.SetActive(false);
         Exit.SetActive(false);
         wonM.SetActive(false);
 
         Trash1.onClick.AddListener(TaskOnClick);
         Trash2.onClick.AddListener(TaskOnClick);
         Trash3.onClick.AddListener(TaskOnClick);
         Trash4.onClick.AddListener(TaskOnClick);
     }
 
     public void TaskOnClick()
     {
         if (won)
         {
             won = true;
             Menu.SetActive(true);
             ViewCreature.SetActive(true);
             Exit.SetActive(true);
             wonM.SetActive(true);
         }
         else
         {
             gameOver.SetActive(true);
 
         }
     }
 
 
     void countDownTimer()
     {
         if (countDownStartValue > -1)
         {
             timerUI.text = " " + countDownStartValue;
             countDownStartValue--;
             Invoke("countDownTimer", 1.0f);
         }
 
         else
         {
             gameOver.SetActive(true);
             FindObjectOfType<Sound>().DeathSound();
             Menu.SetActive(true);
             ViewCreature.SetActive(true);
             Exit.SetActive(true);
             wonM.SetActive(false);
         }
     
     }
         
 
 }
 

Comment
Add comment · Show 1
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 xxmariofer · Jul 28, 2020 at 09:55 AM 0
Share

you have not explained the issue

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Llama_w_2Ls · Jul 28, 2020 at 10:15 AM

Well you could have an int called score increase by one every time you press any button. Then, you can compare your score by saying if (score >= winValue) then output a win message, and move on to the next scene or next level by writing SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1). If the score you got is not enough, meaning you didnt click all the buttons if (score < winValue then you can output a game over message and also reload the scene by typing SceneManager.LoadScene(SceneManager.GetActiveScene()) Hope it helps @d076696

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 Llama_w_2Ls · Jul 28, 2020 at 10:17 AM 0
Share

Its important to add your scenes to the build settings window before you run your game!

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

134 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 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

Animation works only once on button click 4 Answers

Button OnClick() calling wrong function 1 Answer

Add different input for On Click event (UI) 0 Answers

My button does not assign any variable value,My OnClick button works with Debug.Log, but doesnt assign any values it should 0 Answers

OnClick() animation 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