minigame node particles and despawn timer
This commit is contained in:
parent
851b7ae0da
commit
06fde8ab2e
File diff suppressed because it is too large
Load Diff
|
@ -13,6 +13,16 @@ public class EssenceNodeController : MonoBehaviour
|
||||||
private bool followPlayer = false;
|
private bool followPlayer = false;
|
||||||
private Transform player;
|
private Transform player;
|
||||||
|
|
||||||
|
private float timer;
|
||||||
|
private Material nodeMaterial;
|
||||||
|
|
||||||
|
private Coroutine decayCo;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
nodeMaterial = GetComponent<Renderer>().material;
|
||||||
|
}
|
||||||
|
|
||||||
public void Touched()
|
public void Touched()
|
||||||
{
|
{
|
||||||
if (!isTouched)
|
if (!isTouched)
|
||||||
|
@ -20,6 +30,7 @@ public class EssenceNodeController : MonoBehaviour
|
||||||
GetComponent<Renderer>().material.color = Color.cyan;
|
GetComponent<Renderer>().material.color = Color.cyan;
|
||||||
chime.Play();
|
chime.Play();
|
||||||
isTouched = true;
|
isTouched = true;
|
||||||
|
StopCoroutine(decayCo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +38,7 @@ public class EssenceNodeController : MonoBehaviour
|
||||||
{
|
{
|
||||||
followPlayer = true;
|
followPlayer = true;
|
||||||
player = GameObject.FindGameObjectWithTag("MainCamera").transform;
|
player = GameObject.FindGameObjectWithTag("MainCamera").transform;
|
||||||
StartCoroutine(Despawn());
|
StartCoroutine(Collect());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,16 +47,33 @@ public class EssenceNodeController : MonoBehaviour
|
||||||
chime.pitch = value;
|
chime.pitch = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetTimer(float seconds)
|
||||||
|
{
|
||||||
|
timer = seconds;
|
||||||
|
decayCo = StartCoroutine(Decay());
|
||||||
|
}
|
||||||
|
|
||||||
IEnumerator Despawn()
|
|
||||||
|
IEnumerator Collect()
|
||||||
{
|
{
|
||||||
yield return new WaitForSeconds(2f);
|
yield return new WaitForSeconds(2f);
|
||||||
//TODO: Update value in player inventory
|
//TODO: Update value in player inventory
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerator Decay()
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(timer);
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
|
if (!isTouched)
|
||||||
|
{
|
||||||
|
//A way to either linearly reduce the alpha value of color or fade the color to gray (must react to changing timer values)
|
||||||
|
}
|
||||||
|
|
||||||
if (followPlayer)
|
if (followPlayer)
|
||||||
{
|
{
|
||||||
transform.position = Vector3.Lerp(transform.position, new Vector3(player.position.x,player.position.y - 0.5f, player.position.z), Time.deltaTime);
|
transform.position = Vector3.Lerp(transform.position, new Vector3(player.position.x,player.position.y - 0.5f, player.position.z), Time.deltaTime);
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class WellController : MonoBehaviour
|
||||||
private List<GameObject> nodes = new List<GameObject>();
|
private List<GameObject> nodes = new List<GameObject>();
|
||||||
|
|
||||||
public float spawnDelay;
|
public float spawnDelay;
|
||||||
//public float despawnTime;
|
public float despawnTime;
|
||||||
|
|
||||||
|
|
||||||
private Transform player;
|
private Transform player;
|
||||||
|
@ -39,6 +39,7 @@ public class WellController : MonoBehaviour
|
||||||
{
|
{
|
||||||
if(i == numberOfNodes)
|
if(i == numberOfNodes)
|
||||||
{
|
{
|
||||||
|
yield return new WaitForSeconds((despawnTime - spawnDelay) * 2); //Wait for all of the nodes to despawn
|
||||||
foreach(GameObject node in nodes)
|
foreach(GameObject node in nodes)
|
||||||
{
|
{
|
||||||
node.GetComponent<EssenceNodeController>().FollowPlayer();
|
node.GetComponent<EssenceNodeController>().FollowPlayer();
|
||||||
|
@ -49,18 +50,15 @@ public class WellController : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
GameObject tempNode = Instantiate(node, nodeSpawn, Quaternion.identity);
|
GameObject tempNode = Instantiate(node, nodeSpawn, Quaternion.identity);
|
||||||
|
tempNode.GetComponent<EssenceNodeController>().SetTimer(2f);
|
||||||
tempNode.GetComponent<AudioSource>().pitch = pitch;
|
tempNode.GetComponent<AudioSource>().pitch = pitch;
|
||||||
nodeSpawn = nodeSpawn + right * rightDistance + Random.Range(minDown, maxUp) * up;
|
nodeSpawn = nodeSpawn + right * rightDistance + Random.Range(minDown, maxUp) * up;
|
||||||
yield return new WaitForSeconds(spawnDelay);
|
yield return new WaitForSeconds(spawnDelay);
|
||||||
|
StartCoroutine(SpawnNode(nodeSpawn, pitch, i + 1));
|
||||||
|
yield return new WaitForSeconds(despawnTime - spawnDelay);
|
||||||
if (tempNode.GetComponent<EssenceNodeController>().isTouched)
|
if (tempNode.GetComponent<EssenceNodeController>().isTouched)
|
||||||
{
|
{
|
||||||
nodes.Add(tempNode);
|
nodes.Add(tempNode);
|
||||||
StartCoroutine(SpawnNode(nodeSpawn, pitch + 0.1f, i + 1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Destroy(tempNode);
|
|
||||||
StartCoroutine(SpawnNode(nodeSpawn, pitch, i + 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,7 @@ MonoBehaviour:
|
||||||
node: {fileID: 3467985268477833302, guid: 1e00d72d45b494a4ea598ff34d46a589, type: 3}
|
node: {fileID: 3467985268477833302, guid: 1e00d72d45b494a4ea598ff34d46a589, type: 3}
|
||||||
numberOfNodes: 5
|
numberOfNodes: 5
|
||||||
spawnDelay: 1
|
spawnDelay: 1
|
||||||
|
despawnTime: 2
|
||||||
rightDistance: 0.1
|
rightDistance: 0.1
|
||||||
maxUp: 0.2
|
maxUp: 0.2
|
||||||
minDown: -0.2
|
minDown: -0.2
|
||||||
|
|
|
@ -157,6 +157,7 @@ PlayerSettings:
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
- {fileID: 0}
|
- {fileID: 0}
|
||||||
|
- {fileID: 0}
|
||||||
metroInputSource: 0
|
metroInputSource: 0
|
||||||
wsaTransparentSwapchain: 0
|
wsaTransparentSwapchain: 0
|
||||||
m_HolographicPauseOnTrackingLoss: 1
|
m_HolographicPauseOnTrackingLoss: 1
|
||||||
|
|
Loading…
Reference in New Issue