Cycle NPC animations after certain time has passed
Hello,
I am currently attempting to script an NPC pet to execute specific animations based on two timers counting down that would represent their needs. Each timer would represent a need bar that is gradually depleting, and once one reaches zero, an animation would play (for example the pet would look down sadly when a hunger timer reaches zero). I'm a beginner to scripting but I'd like to modify this script to meet my needs:
using UnityEngine; using System.Collections;
public class time : MonoBehaviour {
public bool idle = false;
public float timeToIdle = 2.0f; //2 seconds
float currentTime = 0f;
// Use this for initialization
void Start () {
currentTime = Time.time + timeToIdle;
}
// Update is called once per frame
void Update () {
if(!idle) //this can be replaced by something to check if there is no input etc..
{
checkIdle();
}
}
void checkIdle()
{
if(Time.time > currentTime)
{
idle = true;
//run your anim here or a seperate function to translate the boolean value
currentTime = Time.time + timeToIdle;
}
}
}
Any help at all would really be appreciated, as I'm still learning as much as I can about scripting but I have no clue how to do this one. Thanks very much to the kind souls that are able to lend me a hand.
Your answer
Follow this Question
Related Questions
How can I trigger two animation 2 Answers
SCRIPT HELP! NPC as timer,Need Coding Help- NPC GameObject to act as timer 0 Answers
Invoke() does not delay my game timer 0 Answers
How make: Timer with Time.time 1 Answer
Animation Playmaker 1 Answer