Having some problems.

using UnityEngine;

using System.Collections;

public class Test : MonoBehaviour {

public float SizeModifier;

void OnMouseEnter () {

StartCoroutine(ChangeSize(4));

}

void OnMouseExit () {

StartCoroutine(ChangeSize(-4));

}

IEnumerator ChangeSize (float modifier) {

guiText.fontSize += modifier;

}

}

Just wondering why it’s telling me this: Assets/Script/OK.cs(31,17): error CS0266: Cannot implicitly convert type float' to int’. An explicit conversion exists (are you missing a cast?)

Check if this will work.

using UnityEngine;

using System.Collections;



public class Test : MonoBehaviour {

public float SizeModifier;



void OnMouseEnter () {

StartCoroutine(ChangeSize(4));

}



void OnMouseExit () {

StartCoroutine(ChangeSize(-4));

}



IEnumerator ChangeSize (int modifier) {

guiText.fontSize += modifier; // fontSize is int, so you ether cast modifier to int or set parameter as int
yield break;
}

}

it keeps instantly going outand in again, i want a smooth inward animation, and then a smooth outward animation, not instantly.

So I was finding some way to solve this, I came up with this :slight_smile: I tried it in Unity and it works fine for me, tell me if it suits you! (Maybe you could also optimize the code later, anyway it works!)

I used “waitforseconds” function to make it change smoothly as you want, please I would appreciate a lot if you tell me it worked for you! :slight_smile:

PS: if you need more precision, just change the value of the “waitforseconds” function by a lower value. (higher values will make it work instantly as it was before)

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

	public float SizeModifier;

 	void OnMouseEnter () 
	{ 	
		StartCoroutine(ChangeSize(4));
	}
 
	void OnMouseExit () 
	{
			StartCoroutine(ChangeSize(-4));
	}

 
 	IEnumerator ChangeSize (int modifier) 
	{
		if (modifier<0)
		{
			modifier=modifier*-1;
			
			for (int i=0; i< modifier; i++)
			{
				guiText.fontSize -= i+1; 
				yield return new WaitForSeconds(0.05f);
			}	
			
		}		
		else
			
		for (int i=0; i< modifier; i++)
		{
			guiText.fontSize += i+1; 
			yield return new WaitForSeconds(0.05f);
		}	
	}
	
	
 

}

the text SHOULD stay the same size when the mouse is on the text, when it isn’t any more, the text should go back to the normal size.

sorry I really don’t understand what you want, could you explain a little more? Because in the first script you assume that you wanted to increase the size of the text when the mouse is over it.

the text should be increasing it’s size, not decreasing, and not be repeating whenever the Mouse is on the text…

when the mouse is ON the text, the text enlarges a bit and STAYS that size until the Mouse isn’t on the text anymore, then when the mouse ISN’t on, the text decreases to the normal size…

Hello?

Oh now I understand what’s happening here, I was going crazy >< !!! My script does work but only if you set the value of the guitext size in the inspector, here: 1261489--55395--$ayuda.png for example I set it for 20, you can try this and tell me if it worked, because if the initial value is 0 it won’t work the way you want.

Thanks! it works now! ^^

ok, now i have another problem…

MissingComponentException: There is no ‘Renderer’ attached to the “OK” game object, but a script is trying to access it.
You probably need to add a Renderer to the game object “OK”. Or your script needs to check if the component is attached before using it.
Start.OnMouseExit () (at Assets/Script/Start.js:6)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents(Int32, Int32)

What Renderer? the color when the mouse is on the tect SHOULD be yellow, and when it’s not on, it should turn back to white, but the color stays white…?

here’s the script.

function OnMouseEnter(){
renderer.material.color=Color.yellow;
}

function OnMouseExit(){
renderer.material.color=Color.white;
}

function OnMouseUp(){
Application.LoadLevel(1);
}

Oh yeah! I’m happy now haha, don’t use “renderer” for guitext just use it like this:

function OnMouseEnter(){
guiText.material.color=Color.yellow;
}

function OnMouseExit(){
guiText.material.color=Color.white;
}

function OnMouseUp(){
Application.LoadLevel(1);
}

ok, thanks! ^^