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 Gilead7 · Feb 08, 2016 at 08:00 PM · c#triggersonclick

function call inside OnClick Event?

I'm working with an Event System trigger on the 2d app. I was finally able to get the triggers to work onEnter, onExit, and onClick. With the onClick, I wanted to bring up a dialog box to confirm the selection( in this case to delete the item selected.) For whatever reason, the dialog function is not called.

 public void GoEnter()
         {
             Debug.Log("you entered");
             IDText = MemberID.GetComponent<Text> ();
             IDText.color = Color.red;
             NameText=MemberName.GetComponent<Text>();
             NameText.color=Color.red;
         }
         
         
 public void GoExit()
         {
             Debug.Log("you exited");
             IDText.color = Color.white;
             NameText.color=Color.white;
         }
         
 
 
 
 public void GoClick()
         {
             IDText = MemberID.GetComponent<Text> ();
             IDText.color = Color.green;
             NameText=MemberName.GetComponent<Text>();
             NameText.color=Color.green;
             Debug.Log("you clicked");
             DeleteWindow();
         }


Comment
Add comment · Show 4
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 Owen-Reynolds · Feb 08, 2016 at 08:03 PM 0
Share

You are allowed to call functions from inside an OnClick, OnEnter ... . They work the same as calling any other function any other time. So that's not the problem.

avatar image Gilead7 · Feb 08, 2016 at 08:45 PM 0
Share

Any ideas Owen?

avatar image ClearRoseOfWar · Feb 08, 2016 at 08:50 PM 0
Share

I think you meant

public void OnClick()

avatar image Owen-Reynolds ClearRoseOfWar · Feb 08, 2016 at 11:13 PM 1
Share

Well, the OP wrote that onEnter and onClick were working, so they must have been spelled correctly, etc... at one point (but who knows.)

Q's like this, you pretty much have to walk someone through the whole process. For example, the title is about a function call from OnClick, but the code below shows a completely different thing. So you know you have to start from basics to find the problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Gilead7 · Feb 10, 2016 at 01:03 AM

Come to find out, if you change the event to OnClick, OnEnter, OnExit, you do not need an event system added in. That does solve one problem, but I still cannot call any functions outside of this script. I added the reference at the top, but I get a null reference every time I try to access it. For whatever reason, it will not let me put anything(script or game object) into the public reference in the inspector. I don't get it! Please help! Save my sanity!

     public Script2 _script2; --reference to test script
 
     public void OnClick()
     {
         IDText = MemberID.GetComponent<Text> ();
         IDText.color = Color.green;
         NameText=MemberName.GetComponent<Text>();
         NameText.color=Color.green;
         Debug.Log("you clicked");
         _script2.HelloScript2();
     }
 
 
 Script2
 
     public void HelloScript2()
     {
         Debug.Log("Hello Script 2! This is Script 1 Calling!");
     }
 

alt text


help.jpg (122.5 kB)
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

83 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

Related Questions

Not able to add forces to a Rigid Body Game Object from a script attached to another Game object which is a Trigger. 0 Answers

OnClick() event script from a prefab 0 Answers

Check if character has entered trigger, if it has play animation on character. 1 Answer

[SOLVED] How to Store Object Player Entered Trigger of? 1 Answer

Null Reference Exception only in second method 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