Question by
the_american_fox · Mar 12, 2018 at 02:15 PM ·
c#images
how do you change a raw image in unity using c#
I am trying to make a main menu in unity with multiple images problem is i cant figure out how to go about creating code to change the image when you hover over the button with your mouse.
here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class imagechange : MonoBehaviour
{
[SerializeField] private Image newimage;
[SerializeField] private Image oldimage;
private void OnMouseEnter()
{
//this will change the image from not hovered to hovered
newimage.enabled = true;
oldimage.enabled = false;
}
private void OnMouseExit()
{
//this will change the image from hovered to not hovered
newimage.enabled = false;
oldimage.enabled = true;
}
}
i cant get the images into the variables so I can change the image.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is It Possible To Load 2 images And Compare Them using Edge Detection 0 Answers
Load External JPG as TextAsset 1 Answer
How can I change one canvas image to another? 1 Answer
How can I programmatically instantiate prefabs at locations defined by a color in an image? 0 Answers
How to get images from an array visible 0 Answers