When OnMouseEnter starts, i want my text to grow for 1 second, then when OnMouseExit starts, i want my text to shrink for 1 second.
Can anyone help me? (no script, i don’t have one. sorry. )
When OnMouseEnter starts, i want my text to grow for 1 second, then when OnMouseExit starts, i want my text to shrink for 1 second.
Can anyone help me? (no script, i don’t have one. sorry. )
Anyone?
If you’re talking about a GUIText (you need collider to fire OnMouse* events, also you need to set an initial fontSize on the GUIText in the Inspector):
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void OnMouseEnter () {
StartCoroutine(ChangeSize());
}
IEnumerator ChangeSize () {
guiText.fontSize += 4;
yield return new WaitForSeconds(1f);
guiText.fontSize -= 4;
}
}
If you want the “grow” effect and not just a “bang it’s bigger” you would need to use OnMouseOver.
Ok, Thanks!
so what you mean is replace OnMouseEnter with OnMouseOver?
and if you want it to shrink when your mouse exits the button, you should modify the code:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public float SizeModifier;
void OnMouseEnter () {
StartCoroutine(ChangeSize(SizeModifier));
}
void OnMouseExit () {
StartCoroutine(ChangeSize(-SizeModifier));
}
IEnumerator ChangeSize (float modifier) {
guiText.fontSize += modifier;
}
}
This will simply make your text big instantly and smaller when your mouse leaves the area. If you want it to modify its size over time you should do something inside ChangeSize. test if the size reached it’s peak, if not increase it by Time.deltaTime * SizeModifier * Speed;
Can’t add behaviour script TextEnlarge.
The script file does not match the name of the class defined in the script!
i even named it to the correct thing i want to add it in…
You have probably changed the name of the class in the script after its creation. The file name must match the class name, verify that the file is called TextEnlarge too.
…for OnMouseEnter to play a sound when the mouse is on the button, and for another one to play when you click on it.
There is no GUIText attached to OK game object, but a script is trying to access it. What do i need to add?
DON’T worry, i’m not going to do the GUItext thing now.
Does ANYONE know the script for when the mouse is on a text and a sound plays, and when i click on the text another sound plays?
Hello?
Add an AudioSource to the gameobject and call audio.PlayOneShot on its audio clip in your mouse events… but I really suggest you to follow the basic tutorials, because it seems you’re jumping into battle without knowing your weapon
oh ok. by the way, can you help me with this?
http://forum.unity3d.com/threads/184427-Need-helpers-for-health-system
Assets/Script/OK.cs(31,17): error CS0266: Cannot implicitly convert type float' to
int’. An explicit conversion exists (are you missing a cast?)