Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
This question was closed Apr 25, 2018 at 11:53 PM by S_jay1 for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by S_jay1 · Feb 05, 2018 at 08:44 PM · buttonmobilebutton trigger events

Why is my button not working?

I have a button with an Event Trigger with a script attached, but when I touch the button (on a mobile device) it doesn't work. Is there something wrong with my script, or do I need to add something to the button? This is my script:`using System.Collections; using System.Collections.Generic; using UnityEngine;

public class TapToStart : MonoBehaviour {

 public GameObject homeCanvas;
 public GameObject playCanvas;


 void Start () {
     
     homeCanvas = GameObject.Find("HomeScreen").GetComponent<GameObject> ();
     playCanvas = GameObject.Find("PlayCanvas").GetComponent<GameObject> ();

     homeCanvas.SetActive (false);
     playCanvas.SetActive (true);

     GameObject.Find("Player").GetComponent<PlayerController>().enabled = true;
     GameObject.Find("Player").GetComponent<DestroyContact>().enabled = true;
     GameObject.Find("GameSpawner").GetComponent<Instantiater>().enabled = true;
 }

}

`

Comment
Add comment · Show 5
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 hexagonius · Feb 07, 2018 at 09:33 PM 0
Share

well, what does this script has to do with your button? you need an EventSystem, the button on a canvas and a graphicraycaster on your scene (forgot where the raycaster goes).

avatar image S_jay1 hexagonius · Feb 08, 2018 at 12:02 AM 0
Share

I have all of those items, but for some reason, I still can't click the button. I looked at this post https://answers.unity.com/questions/889908/i-created-an-ui-button-but-click-does-not-work.html to try to solve my problem, but nothing worked, which is why I thought it was my script that was the issue.

avatar image Sajjad_shaikh · Feb 08, 2018 at 06:19 AM 1
Share

what you are trying to do? the code u have attached is having only start method which execute when script execute.

avatar image S_jay1 Sajjad_shaikh · Feb 08, 2018 at 07:40 PM 0
Share

I'm trying to create a tap to start button for my game, so when the button is clicked, the home screen canvas is disabled and the game screen canvas is enabled.

avatar image UnitedCoders · Feb 08, 2018 at 07:23 AM 0
Share

$$anonymous$$ake sure you have EventSystem enable in your hierarchy .

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by gon777 · Feb 08, 2018 at 07:47 AM

If you cannot interact with the button, for example click but button not pushed down, make sure there is no invisible panel (with Raycast Target 'on') or something else on top of that button.

If you can click the button but nothing happens, make sure you register OnClick() event properly.

Event trigger works with input event, like OnPointerEnter() etc. I am not sure what event you used, and not sure what you're trying to achieve, but if you want click event just use OnClick() event in Button component.

Yep, like the other answer says, check event system is in the scene as well.

Edit: Formating, Grammar

Comment
Add comment · Show 15 · 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 S_jay1 · Feb 08, 2018 at 07:46 PM 0
Share

I have the RayCast Target box checked in the hierarchy and there is nothing blocking the way of the button. I think I have the OnClick registered properly, and I removed the event trigger part from the hierarchy.

alt text

Basically, I want to create a tap to start button but I can't use timescale = 0 and then 1 because I have a particle effect playing and if I do that, it pauses it.

button.png (17.6 kB)
avatar image gon777 S_jay1 · Feb 09, 2018 at 01:12 PM 0
Share

I think you are not registering event properly. $$anonymous$$y suggestion is, create a method call 'OnTapToStart()', then register OnTapToStart() in OnClick()

In OnTapToStart(), disable your canvas there:

 void OnTapToStart()
 {
     homeCanvas = GameObject.Find("HomeScreen").GetComponent();
     playCanvas = GameObject.Find("PlayCanvas").GetComponent<GameObject>();
     homeCanvas.SetActive(false);
     playCanvas.SetActive(true);
     GameObject.Find("Player").GetComponent<PlayerController>().enabled = true;
     GameObject.Find("Player").GetComponent<DestroyContact>().enabled = true;
     GameObject.Find("GameSpawner").GetComponent<Instantiater>().enabled = true;
 }

Also try to avoid find objects, it will slow down your game when things get messy. Try to drag and drop your canvas object to your script.

If you want to play a particle effect, create a prefab and attach particle effect to it, instantiate the prefab when tap the button.

Try not to use Start() as a function name unless you know what you are doing, Start() is invoked automatically when script is enabled.

avatar image S_jay1 gon777 · Feb 09, 2018 at 08:48 PM 0
Share

What do you mean by register OnTapTOStart() in Onclick()? Do you mean to change this part alt text

I changed the script to this`using System.Collections; using System.Collections.Generic; using UnityEngine;

public class TapToStart : $$anonymous$$onoBehaviour {

 public GameObject homeCanvas;
 public GameObject playCanvas;

 void OnTapToStart(){

     homeCanvas.SetActive (false);
     playCanvas.SetActive (true);

     GameObject.Find("Player").GetComponent<PlayerController>().enabled = true;
     GameObject.Find("Player").GetComponent<DestroyContact>().enabled = true;
     GameObject.Find("GameSpawner").GetComponent<Instantiater>().enabled = true;



 }

}

but it's still not working. I have the script dragged onto my canvas with the gameobjects attached alt text

ontaptostart.png (20.1 kB)
taptostart.png (8.4 kB)
Show more comments
avatar image
0

Answer by SQ_11 · Feb 08, 2018 at 07:49 AM

Check Event System is there in Hierarchy. If it is there, then in Inspector Window, check Force Module Active true. Check again it works or not.

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 S_jay1 · Feb 08, 2018 at 07:42 PM 0
Share

I have the Event System in the Hierarchy with the Force $$anonymous$$odule Active box checked, but it's not working. Do I need to put something in the First Selected part of the hierarchy?

Follow this Question

Answers Answers and Comments

92 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

Related Questions

How to make an object keep move when pressing a button? 0 Answers

How do I control my car with UI buttons? 0 Answers

CrossPlatformInput Detect Multiple Input Headache 1 Answer

Multiple mobile devices 0 Answers

how can I specify an area based on a proportion of the screen height/width and have a jump/move image there? 2 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