Hello I'm new to Unity and I'm trying to make a UI button change its Source Image when the mouse is over it, and when the mouse is no longer over the button, the button's Source Image is back to normal. I know that a sprite is needed to be the button's source image, so I created two image sprite files (one being the normal image and the other being the light-up image when the mouse hovers over the button)
Now here is a screenshot of the play button having its normal source image
Button will change its source image by lighting up when mouse goes over it
How do I do this task in C#? How do I change the source image of the button in C# when the mouse hovers over it?
This is what I got so far after looking at some references. I'm new to Unity so sorry for my lack of knowledge
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayButton : MonoBehaviour {
private PlayButton pb;
private Sprite newSprite;
// Use this for initialization
void Start () {
pb = GetComponentInChildren<PlayButton> ();
}
// Update is called once per frame
void Update () {
}
public void onClick(){
}
public void onPointerHover(PointerEventData eventData){
//When mouse hovers over the button, the button changes
pb.image.overrideSprite = newSprite;
}
}