Add cat meow and follow
This commit is contained in:
1 parent
9c5d74f65f
commit
0a75d2bf98
12 files changed
+1322
-861
No files matched your search
@@ -0,0 +1,46 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class FollowerController : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
public float wakeDistance;
|
||||
|
||||
private NavMeshAgent agent;
|
||||
private AudioSource audioSource;
|
||||
private Animator[] anims;
|
||||
private bool isFollowing = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
agent = GetComponent<NavMeshAgent>();
|
||||
anims = GetComponentsInChildren<Animator>();
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (isFollowing)
|
||||
{
|
||||
foreach (var anim in anims)
|
||||
{
|
||||
anim.SetFloat("speed", agent.velocity.magnitude);
|
||||
}
|
||||
//Debug.Log($"Velocity: {agent.velocity.magnitude}");
|
||||
agent.SetDestination(target.position);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dist = Vector3.Distance(target.position, transform.position);
|
||||
isFollowing = dist < wakeDistance;
|
||||
if (isFollowing)
|
||||
{
|
||||
audioSource.Play();
|
||||
Debug.LogWarning("Played the audio!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user