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 /
avatar image
0
Question by TheNinjassin · Mar 10, 2016 at 10:29 AM · uibuttonreferenceonclick

Reference For Button Which Calls OnClick

Hi guys.

I have some buttons which each have an OnClick reference (in the inspector) to my UI handling script. The effect I want to produce is (in part) that when the button is clicked Effect A will happen and the button will disappear. The only thing I could think of to do this was to add a parameter to the function which passes in the GameObject for the button which I would then have to assign in the inspector. This seems somewhat convoluted. Is there an alternative way that I can reference the button which called the function from within the function?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MrAlter · Mar 11, 2016 at 08:09 AM

I think better solution is pass link to button as parameter:

 public void OnClick(Button button) {
     button.gameObject.SetActive(false);
 }

Also you can receive link to clicked GameObject by EventSystem:

 public void OnClick() {
     EventSystem.current.currentSelectedGameObject.SetActive(false);
 }

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 deffitaredina · Mar 10, 2016 at 01:50 PM

you need a script that is similar but different names, and enter the script in evenstystem !!!

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 deffitaredina · Mar 10, 2016 at 01:50 PM

pragma strict

public var currentMount : Transform; public var speedFactor : float = 0.1;

function Start () {

}

function Update () {

 transform.position = Vector3.Lerp(transform.position,currentMount.position,speedFactor);
 transform.rotation = Quaternion.Slerp(transform.rotation,currentMount.rotation,speedFactor);

}

function setMount(newMount : Transform){ currentMount = newMount; }

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 deffitaredina · Mar 10, 2016 at 10:40 AM 0
Share

use this, but yoiu need current mount for moving your camera in one click

avatar image
0

Answer by zulfiqar-younus · Mar 11, 2016 at 12:09 AM

make static class and use that class for your effect to play . here is the rough code for this.

publi myClass {

public static PlayEffect() { ///your work } }

void OnClick() { myClass.PlayEffect();/ gameObject.setactive(false); }

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

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

57 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

Related Questions

UI Button OnClick Function - How to get name of button that was clicked? 2 Answers

Button.onClick.AddListener(() => Attack()); isn't running function math correctly 1 Answer

Change variable value using new UI Button 2 Answers

Functions aren't appearing in the onClick editor..... 1 Answer

UI Button generated in runtime OnClick event 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