How to activate UI element on mouse over?
Hi All,
Just working on a school project and I came into an issue. Previously I've used on mouse over to make text activate/deactivate in the game world. However it doesn't seem to work on UI features. I was attempting to make a semi-transparent panel activate/deactivate on mouse over for a UI effect. Does anyone know what I need to do to make this happen? I have heard of on pointer enter, will this accomplish what I need?
Many thanks in advance.
Answer by tormentoarmagedoom · May 08, 2019 at 09:41 AM
HEllo.
Using SetActive(true) or (false) is used in GameObjects, to activate and deactivate the whole gameobjects and all its componentes.
But you can enable/disable specyfic compoentns like this:
Object.GetComponent<Renderer>().enable = true; (or false)
Then you say " However it doesn't seem to work on UI features" and thats not true. What is happening i supose, is that you are trying to activate a object from a script in that object, and that object is not active, so the script is not active adn can not detect the mouse!
You need to rethink it! You can not deactivate the whole object if want the script to be enabled.. If its a UI element, you can simple enable=false the Image compoenent , or rendere component, so it will be "inivisible" but it will be there running the script waiting to detect the mouse.
Understand?? :D
Good luck! Bye!
Your answer
Follow this Question
Related Questions
Windows-like scalable panels in Unity? 0 Answers
how do i take whats on one UI canvas and make it apear on another in real time(for a card game) 0 Answers
How would i modify my current script to remove these UI buttons without killing my pause menu? 1 Answer
How to fade in and out two panels in a scene? (c#) 1 Answer
C# GameObject disabled scripts of its children after SetActive(false) 1 Answer