- Home /
Play animation once in a update
Hello everyone! i have this script
namespace cakeslice
{
public enum Interact
{
teleport,change,other
}
public class MouseOnObject : MonoBehaviour
{
public Interact action;
public GameObject player;
public string inspect;
public GameObject InteractPicture;
public GameObject InspectPicture;
public bool lookonobject = false;
public bool showlabel = false;
public GUISkin s1;
void OnMouseOver()
{
lookonobject = true;
//InteractPicture.GetComponent<Animation>().Play("optionsappear");
//InspectPicture.GetComponent<Animation>().Play("optionsappear");
}
void OnMouseExit()
{
lookonobject = false;
//InteractPicture.GetComponent<Animation>().Play("optionsdisappear");
// InspectPicture.GetComponent<Animation>().Play("optionsdisappear");
}
void Update()
{
if (Vector3.Distance(player.transform.position, this.transform.position) < 3 && lookonobject == true)
{
GetComponent<Outline>().enabled = true;
}
else
{
GetComponent<Outline>().enabled = false;
}
if (lookonobject == true && Input.GetKey(KeyCode.Mouse1))
{
StartCoroutine(LabelShow());
}
}
IEnumerator LabelShow()
{
showlabel = true;
yield return new WaitForSeconds(3);
showlabel = false;
}
void OnGUI()
{
if (showlabel == true)
{
GUI.skin = s1;
GUI.Label(new Rect(Screen.width/3.2f, Screen.height/1.4f, Screen.width/2.5f, Screen.height/3.0f), inspect);
}
}
}
}
There's a two images with 2 animations, attached to player's canvas, how can i make them play animation once and stay in the state at the end of the animation when lookonobject is set to true and vise versa without repeating?
Answer by leftshoe18 · Nov 09, 2018 at 03:59 AM
Would setting up the animation to not loop work?
no, it start again and again no matter what wrap i choose. it was working as inteded as long as i choose to play it on On$$anonymous$$ouseEnter or On$$anonymous$$ouseExit, but i need it to play disappear animation when distance is become more that 3 even if i still looking at it. using On$$anonymous$$ouseOver makes it repeat too
Your answer
Follow this Question
Related Questions
Update character's position after animation 1 Answer
Multiple Cars not working 1 Answer
Play audio.PlayOneShot() once in an Update() function 2 Answers
Distribute terrain in zones 3 Answers
Mouse move to control the animation 1 Answer