Add animations to Shello
This commit is contained in:
1 parent
51de4150c4
commit
3f9ac3eb81
21 files changed
+1472
-229
No files matched your search
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ShelloController : MonoBehaviour
|
||||
{
|
||||
public float notice_distance;
|
||||
|
||||
Transform player;
|
||||
Animator anim;
|
||||
bool isAwake = false;
|
||||
int awokenFrames = 0;
|
||||
|
||||
void Start()
|
||||
{
|
||||
anim = GetComponent<Animator>();
|
||||
var players = GameObject.FindGameObjectsWithTag("Player");
|
||||
if (players?.Length > 0)
|
||||
{
|
||||
player = players[0].transform;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (player == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAwake)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float dist = Vector3.Distance(player.position, transform.position);
|
||||
var isExcited = dist < notice_distance;
|
||||
|
||||
anim.SetBool("isExcited", isExcited);
|
||||
if (isExcited)
|
||||
{
|
||||
awokenFrames++;
|
||||
if (awokenFrames > 120)
|
||||
{
|
||||
anim.SetBool("isExcited", false);
|
||||
anim.SetBool("isWalking", true);
|
||||
isAwake = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user