• 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 Squid117 · May 18, 2015 at 10:18 AM · button

How do I create a clickable object?

I have not exactly made or figured out how it will work yet but there is going to be a script that will alert the player that they need to click the button, and will wait until time runs out and they lose, or until the player clicks the button. I'm guessing this has to do with raycast. I want to know what scripts or components are needed to let the play walk over, click the object, and continue with the script. Please explain all details because I'm fairly new to this. Thank you in advance.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Squid117 · May 19, 2015 at 06:25 AM

Ok, I just found out how to get the button to work and continue the rest of the script. I guess I found the answer to my question... It wasn't what I was looking for but thank you Headworker for your answer. It might be useful when I do start working on UIs.

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
1

Answer by Headworker · May 18, 2015 at 10:33 AM

First you need to decide if the object that should be clicked should be a gameobject or a UI-Element. I think you want the latter.

For this you first need to place a button with the new Unity UI system (look for tutorials how to use, for example start here, official tutorials

Then create a script on the camera.

     // add using UnityEngine.UI at the top
     
     public button MyButton // Drag your button gameobject in this in the inspector
     
 void start()
 {
 MyButton.onClick.AddListener(()=>ButtonWasClicked());
 }
 
 void ButtonWasClicked()
 {
 // whatever you need
 }
 

You can use this method for you logic, to check if the button was clicked.

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 Squid117 · May 18, 2015 at 03:08 PM 0
Share

Uh, no I wanted a button in the game scene, not in a UI.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Getting Buttons to change stage c# Add Listner 1 Answer

Animation not working when UI buttons are pressed 0 Answers

saving button text 1 Answer

How to attach GUI Skin on button? 0 Answers

Invoke other UnityEvent with gameobject.GetComponent().onClick.AddListener(); 2 Answers

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