On-click and trigger animation c#
I'm a complete noob at this, but I'm hoping that the solution to my problem is relatively simple.
I'm trying to make it so when you move close to the dog (within the trigger) it plays the "excited" animation on loop, and when you click on it, it plays the "jump" animation once. The rest of the time it should be playing the "idle" animation.
Here is my attempt, which comes up with a whole bunch of errors..
using UnityEngine;
using System.Collections;
public class Animatedog : MonoBehaviour
{
static Animator anim;
void Update ()
{
if(Input.GetMouseButtonDown)
{
anim.SetTrigger("Jump");
}
else if (OnTriggerStay (Collider other))
{
anim.SetTrigger("Excited");
}
else
{
anim.Play("Idle");
}
}
}
Please help!
line 11: you Need These () behind every function. In case of Input.get$$anonymous$$ouseButtonDown you also need an integer to specify which mouse button should be the trigger (I assume you would want to write Input.Get$$anonymous$$ouseButtonDown(0) for the left mouse button)
I'm not sure but OnTriggerStay does not return a bool so it makes no sense to call it in an if Statement. Also i think it can't be called in scripts but only triggered by a collider being inside a trigger but thats nothing i know for sure. You can either boxcast around the dog and check for the Player or you use OnTriggerStay which you have to set up like this.
void OnTriggerStay(Collider other)
{
anim.SetTrigger("Excited");
}
you have to place this in the class Body outside any function (like Update()) and it must bein the script that is attached to the game object of the trigger.
Answer by isabel128664 · Mar 23, 2018 at 05:25 PM
Need to add 0,1 or 2 in if(Input.GetMouseButtonDown(0)) { }
Your answer
Follow this Question
Related Questions
Bad Response Time for Input.GetKeyDown 1 Answer
The name animator does not exist in the current context... Help? 1 Answer
Play animation on mouse click 1 Answer
Animation play not working C# 0 Answers