- Home /
Changing an objects background image on hover.
Hey guys, I'm back after quite the absence. I'm creating an RPG style game, similar to a mix of the classic RPG game series Might & Magic, mixed with Final Fantasy 10. Anyway, I haven't used C# in forever, and can't figure out how to make an object that I imported from Cinema4D change image textures onHover.
using UnityEngine;
using System.Collections;
public class Load : MonoBehaviour {
public Texture LoadBG;
public Texture LoadBG_Hover;
void Start()
{
setNormal();
}
public void setNormal()
{
renderer.material.mainTexture = LoadBG;
}
public void setHover()
{
renderer.material.mainTexture = LoadBG_Hover;
}
void OnMouseOver()
{
setHover();
}
}
What exactly am I doing wrong?
So what happens? The texture doesn't change at all, or (guessing from code) doesn't change back?
It doesn't change at all, which really baffles me. It's attached to the object, and it sets it to the original image, but doesn't change it to the new one.
Huh... That makes two of us then O.o
I just assumed it doesn't change back, because you only call setNormal() at the start and never again. Are you sure you haven't set both textures to be the same by accident?
Answer by tw1st3d · Jul 07, 2013 at 10:04 PM
Figured out my problem, added a mesh collider to the object and it worked.
Your answer
Follow this Question
Related Questions
Ihave a problem 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Problems with instantiation... 1 Answer
C# Coding error 1 Answer