• 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 Belakeh · May 09, 2017 at 05:42 AM · beginnerbuttonsimage effectscolors

how would i change the colour of an image once I've hovered over a button?

hey so I'm new to unity and I'm trying to make a cool but simple menu for my game ... how would i change the colour of an image once I've hovered over a button? i have already managed to know when i have enter/exited and clicked the button but i have no clue how to change the colour for the image.

I don't know how to explain it much more. for example i have icons for play, settings and volume. what I want to happen is when i hover the mouse over one of the button the bar that i have put across all of them i want to make it change colour.

alt text

in the picture above I'm showing what i mean by the bar.

alt text

in the above photo i have my mouse over the button and it is showing the highlighted colour that i have set for it. this is the type of effect i am looking for but with using a separate button from the bar.

this is the code i have so far. I've been looking everywhere for an answer over the past week and I'm starting to get super annoyed, it's probably something simple but i don't have the knowledge for it yet.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class ButtonTest : MonoBehaviour {

 public Image MenuBar;

 public void OnClick(){
     Debug.Log ("Clicked!");
 }

 public void OnEnter(){
     Debug.Log ("YAY!");

 }

 public void OnExit(){
     Debug.Log ("Aw, sad now");
 }

}

so i know this code works when i hover over the button cause i have set the event triggers to look for these commands. but immmmmmmmmmmmmmmmm sooooooo stuck. please help :)

i349cimgpsh-orig.png (133.0 kB)
bruh.png (4.7 kB)
Comment
Add comment · Show 1
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 path14 · May 09, 2017 at 08:56 AM 0
Share

You'd probably use IPointerEnterHandler Then use GetComponent to get the color of the button.

This is how you'd use it in javascript (you'll have to translate it to C#):

 public class Items extends $$anonymous$$onoBehaviour implements IPointerEnterHandler {

 // i think you can insert the getcomponent call here

 function OnPointerEnter(eventData : PointerEventData){

 // variable(the getcomponent var).color or something like that. I haven't done it with colors, so i'm not too certain, but this is how i would do it. 

 }

} https://docs.unity3d.com/ScriptReference/EventSystems.IPointerEnterHandler.OnPointerEnter.html

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

105 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 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

Cascading dropdown menus 0 Answers

Button with An Active Clickable Area 1 Answer

Is there any way you can make a button that is placed in 2D space and not the canvas? 1 Answer

Controller / movement script rotate while moving HELP 0 Answers

Reference replaces itself with Missing when destroyed, but not consistently 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