71 lines
1.3 KiB
C#
71 lines
1.3 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class Spookys : MonoBehaviour
|
|
{
|
|
public AudioSource AudioSource;
|
|
public RawImage RawImage;
|
|
public Texture2D[] Textures;
|
|
public Texture2D TinkyNear;
|
|
|
|
public bool doNow;
|
|
|
|
float extraTime = 0;
|
|
|
|
private void Update()
|
|
{
|
|
extraTime += Time.deltaTime / 10;
|
|
if (extraTime > 60)
|
|
extraTime = 60;
|
|
}
|
|
|
|
IEnumerator Loop()
|
|
{
|
|
AudioSource.Stop();
|
|
RawImage.enabled = false;
|
|
|
|
while (true)
|
|
{
|
|
float nextTime = Time.time + Random.Range(30f + extraTime, 60f + extraTime);
|
|
yield return new WaitUntil(() => Time.time > nextTime || doNow);
|
|
|
|
if (doNow)
|
|
doNow = false;
|
|
|
|
bool useNearby = false;
|
|
|
|
if (TinkyWinky.Instance) {
|
|
float dist = Vector3.Distance(Player.Instance.transform.position, TinkyWinky.Instance.transform.position);
|
|
if (dist < 50 && TinkyWinky.Instance.ActiveState >= TinkyWinky.States.Stalk)
|
|
{
|
|
useNearby = true;
|
|
}
|
|
}
|
|
|
|
if (useNearby)
|
|
{
|
|
AudioSource.pitch = 0.5f;
|
|
RawImage.texture = TinkyNear;
|
|
} else
|
|
{
|
|
RawImage.texture = Textures[Random.Range(0, Textures.Length)];
|
|
AudioSource.pitch = 1f;
|
|
}
|
|
|
|
RawImage.enabled = true;
|
|
AudioSource.Play();
|
|
|
|
yield return new WaitForSeconds(0.1f);
|
|
|
|
AudioSource.Stop();
|
|
RawImage.enabled = false;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(Loop());
|
|
}
|
|
}
|