Hi, I'm afraid I'm not as proficient with scripting as of yet and I wanted to just make a virtual pet type of simulation game using the new unity 2d features. I wanted it to be so that when you press + hold the left mouse button over the creature and move it around to simulate petting, it would change animation (using a sprite sheet by the way) from it's default/idle animation to it becoming happier because you're petting it. And when you release, it would go back to it's default animation. I managed to do that, but it doesn't seem to matter where I click. I was wondering how I could add to this script to get it to work so that it only changes animation when the mouse is over the creature.
#pragma strict
var anim: Animator;
function Start ()
{
anim = GetComponent("Animator"); //Access character animations.
}
function Update ()
{
if (Input.GetMouseButton(0)) //Press and hold left mouse button to interact.
{
anim.SetTrigger("Rub");
}
else if (Input.GetMouseButtonUp) //Release left mouse button to return to stop interacion.
{
anim.SetTrigger("NoRub");
}
}
↧