Files
PrincessLandVR/Assets/OwlController.cs
T
gunnbr 12145753f0 Make Shello rotate towards the player before jumping (this still needs work)
Convert all scripts to used tagged Player.
Try to keep Shello on the ground while walking (not sure if this works yet).
Fix transition from excitement to walking to happen immediately.
2021-01-17 10:22:11 -08:00

44 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OwlController : MonoBehaviour
{
Animator anim;
Transform player;
public float startle_distance;
// Start is called before the first frame update
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)
{
float dist = Vector3.Distance(player.position, transform.position);
var startled = dist < startle_distance;
anim.SetBool("Startled", startled);
if (dist < startle_distance)
{
Debug.LogError($"Startled at {dist}");
}
foreach (var childAnim in GetComponentsInChildren<Animator>())
{
childAnim.SetBool("Startled", startled);
}
}
}
}