Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by kevinamoin23 · Sep 11, 2016 at 01:32 PM · uibutton

Hello. what is the correct condition in which I want the player to pressed a UI button please help! :(

                if(Input.GetButtonDown(interactButton)) // this button is from the Input setting where the Interact button is actually a "MOUSE 0" a.k.a Left click and I want this to change to UI button when the player pressed something happens. I dont know how to do that :'( Please help :'(
                 {
                                //My statement :)
                  }

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

1 Reply

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

Answer by ArturoSR · Sep 12, 2016 at 01:06 AM

Hello there.

OK, to make the user interact with you app using the new UI system in unity is as follows:

  1. Create a component (script) with a public method/function and attach it to an empty game object or whatever you choose.

  2. Create a UI-Button using the menu item: Game Object > UI > Button.

  3. Select the new button and drag & drop the game object with the component that you create.

  4. Use the drop down menu to select the method/function that you defined within your component, example: public void MakeALotOfNoise() { }, where MakeAlotOfNoise will be the choice.

So, as you can see there's how to make a Button do something inside your app, if you require more info about the new UI, check the documentation, cheers.

Comment
Add comment · Show 2 · 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 kevinamoin23 · Sep 12, 2016 at 11:48 AM 0
Share

Thank you sir for the response I know that thing but my point is How can I changed that key control in which a $$anonymous$$ouse Button to change to a UI button that when pressed the door Opens. and it is in the Update method which attached to my FPS control? It is possible to do that? I dont know how. Newbie here Please help :(


public string interactButton; public Layer$$anonymous$$ask interactLayer; public Image interactIcon; public bool isInteracting;

 public float interactDistance = 2f;

 void Start()
 {
     if (interactIcon != null)
     {
         interactIcon.enabled = false;
     }
 }
     void Update() {

         Ray ray = new Ray (transform.position, transform.forward);
         RaycastHit hit;
         if (Physics.Raycast (ray, out hit, interactDistance , interactLayer)) 
         {
             if (isInteracting == false)
             {
                 if(interactIcon != null)
                 {
                     interactIcon.enabled = true;
                 }
                if(Input.GetButtonDown(interactButton)) //This is I want to changed to a Button when pressed :( It is possible to make the update public so that we can attached it to a button on click? Please help.
                 {
                     if (hit.collider.CompareTag("Door"))
                     {

                         hit.collider.transform.parent.GetComponent<Door>().ChangeDoorState();
                     }
                     else if(hit.collider.CompareTag("$$anonymous$$ey"))
                     {
                     hit.collider.GetComponent<$$anonymous$$ey>().UnlockDoor();
                     }

                 }
            }
         }
         else
         {
         interactIcon.enabled = false;
         }
 }
avatar image ArturoSR kevinamoin23 · Sep 12, 2016 at 02:49 PM 0
Share

If you want to interact directly with your mouse, you need to replace the transform.forward by mouse.position, using the raycast you can control the raycast direction exactly where the mouse cursor point it, again, you can read more about it in the ducumentation, cheers.

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

80 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

Related Questions

How to play different animations with different UI button presses. 1 Answer

How to switch cameras with ui buttons? 0 Answers

find an especific multitouch wich is on a image in the canvas 0 Answers

How to find an UI button by name? 2 Answers

Text on UI Button Not Updating 1 Answer


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