Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 jaja1 · Jan 26, 2015 at 12:46 AM · c#uievent triggering

Event Trigger trouble (4.6 UI)

alt text

I am trying to implement a system for an exp bar where the player hovers the mouse over the bar and it displays the current exp percentage. I am using the new ui system (4.6) and event triggers on a blank image that is placed over the actual exp bar. The setup on my trigger system is shown in the screen shot. The script implemented to display the exp percentage is as shown below:

 public class Exp_Bar : MonoBehaviour 
 {
     bool isHovering = false;
 
     void OnGUI()
     {
         if (isHovering)
         {
             decimal exp = (decimal)Math.Round((active_player_profiler.plvl_exp / 1000f) * 100f, 2);
             GUI.Box(new Rect(Input.mousePosition.x + 15f, Screen.height - Input.mousePosition.y, 70f, 20f), exp.ToString() + "%");
             Debug.Log("yooooooo");
         }
     }
 
     public void enableHover()
     {
         isHovering = true;
         Debug.Log("enabled");
     }
 
     public void disableHover()
     {
         isHovering = false;
         Debug.Log("disabled");
     }
 
 }

I placed the debug messages for testing purposes. When in game, nothing seems to work. I don't see the debug messages or the exp display. Also, I removed the EventSystem object as a test. I had it before on my canvas but it did not fix the issue. My canvas also has its default graphic raycaster. What seems to be the problem?

untitled.png (138.6 kB)
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 SneeKeeFahk · Jan 26, 2015 at 03:19 AM

I think you are missing an EventSystem object in your scene. Try adding one or add a new Canvas and that should add one for you.

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 jaja1 · Jan 27, 2015 at 12:30 PM 0
Share

Though if you were to read over the OP I did mention adding an eventsystem, the problem was I had the standalone input module disabled. For PCs and $$anonymous$$acs it needs to be enabled if you plan on using events that involve mouse input. I can disable the touch input module in this case because it is not needed. Thank you @Snee$$anonymous$$eeFahk :)

avatar image
1

Answer by SnStarr · Jan 26, 2015 at 02:55 AM

In order to use the new UI system in Unity you need to add Using statements. Above the Class declaration of public class Exp_Bar : MonoBehaviour should be using UnityEngine.EventSystems and the script should also inherit from the IPointerClickHandler if using OnPointerClick events.

 using UnityEngine;
 using UnityEngine.EventSystems;
 public class Exp_Bar : MonoBehaviour, IPointerCLickHandler
 {
 bool isHovering = false;
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 jaja1 · Jan 27, 2015 at 12:28 PM 0
Share

Even though this did not quite solve my issue I am voting up because I did not know this and also opened up some of my options for future code.

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

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What's your equivalent of old GUIStyle ? 0 Answers

How do you add an UI EventTrigger by Script ? 6 Answers

How to set EventTrigger parameters by C#? 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