Hover - issue

Hello,

I am having some hover over button issues and am really hoping someone can help?

I set up a GUI skin and created 10 Images (buttons, that dont look like buttons) for the hover state 10 more/different images.

When I hover over these images the new image replaces the old one which is great but how would I hover over these images and also have a sound play? Here is my original script:

var strings : GUISkin;

var s1X : float = 200;
var s1Y : float = 10;

function OnGUI()
{
	GUI.skin = strings;
	
	GUI.Button (Rect (s1X, s1Y, 189,26), "","s2");
}

I read some posts and changed it to this but this wont work because it turns my image into a button?

var hover : String;
var strings : GUISkin;

var s1X : float = 200;
var s1Y : float = 10;

function OnGUI()
{
	GUI.skin = strings;
	
	GUI.Button (Rect (s1X, s1Y, 189,26), GUIContent ("s1","s1"));
	
	hover = GUI.tooltip;	
}
function Update()
{
	if(hover=="s1")
	{
		Debug.Log("sound Played");	
	}	
}

Soooo… How would I script having a image and when I hover over it the image will change to a different image but also play a sound?

What do you mean turns my image into a button?
You could use a label instead.

Using the second script above turns the image I have into the Unity default style looking button and removes my image.

What Im trying to achieve is to simply have an image on screen and when my mouse hovers over that image, it will change to a different image and then when my mouse exits that image it will go back to the original image and play a sound. I thought this would be simple to do but now Im really scratching my head.

I have just tried doing it using GUITextures and did the first one which worked and thought yes I finally got it until I added 9 more then half of them did not work anymore and some would work periodically or not at all :frowning: I need to do this for 10 images.

here’s another failed attempt:

var stringNumber : int = 0;//which string am I 

var oneG : AudioClip; 
var twoA : AudioClip;

var stringRegular : Texture2D;
var stringGlow : Texture2D;

function OnMouseOver()
{
	if(stringNumber == 1)
	{
		guiTexture.texture = stringGlow;
	}
	if(stringNumber == 2)
	{
		guiTexture.texture = stringGlow;
	}	
}

function OnMouseExit()
{
	if(stringNumber == 1)
	{
		guiTexture.texture = stringRegular;		
		this.audio.PlayOneShot(oneG);
		//audio.volume = .2;
	}
	if(stringNumber == 2)
	{
		guiTexture.texture = stringRegular;
		this.audio.PlayOneShot(twoA);
	}		
}

So Im really not sure how to do it :frowning: Any suggestions?

Oh… I tried using a label as you suggested but that didn’t seem to work either?

your answer is here: http://answers.unity3d.com/questions/125575/playing-audioclip-on-mouseover.html?sort=oldest

Thanks!

I decided to go with EZ Gui already but greatly appreciated!