Hi, I’m currently trying to make a simulation game (kind of like tamagotchi) where you nurture a pet through different interactions. I used a sprite sheet in unity 2d and spliced them to make the different animations needed. (idle, fed, hungry, etc). And I used this code on the Pet’s game object
var anim : Animator;
function Start()
{
anim = GetComponent("Animator");
}
function Update()
{
if(Input.GetMouseButton(0) == false)
{
anim.SetTrigger("NoRub");
}
}
function OnMouseOver()
{
if(Input.GetMouseButton(0))
anim.SetTrigger("Rub");
}
So that it plays the ‘Rub’ transition animation when you rub the pet (left mouse + hold) to make him happy and returns to idle state (which is just bobbing up and down) when you stop. Anyway, my question is how can I reference the pet animation in another script, for example a ‘feed button’? so it triggers the animation after a click and then reverts back to idle as usual.
I’m not the best at coding and I was wondering if anyone can help me create a variable in the other scripts which is an animator type so that this could work? In one attempt, i tried dragging the animator from the pet into the other script’s swatches in the inspector but the feedbutton turned into the pet.