Hello, I am trying to get an animation to play when I click an object with the attached animation. I used OnMouseOver to check if the mouse is hovering over the object, then I used Input to get the left mouse button. After the input is checked, an animation is coded to play. Problem is, it will not play.
I get no errors with this script, but nothing happens. My Debug.Log’s return the strings to the console, so I know my crap is working. Please, can someone help me? I gotta go to sleep.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ContainerOpen : MonoBehaviour
{
void OnMouseOver()
{
Debug.Log ("screw you");
if (Input.GetMouseButton (0))
{
Debug.Log ("you clicked this piece of shit, now good luck playing an animation");
gameObject.GetComponent<Animation>().Play("TopLeftDeskDrawer|OpenClose");
}
}
}