Added NoTrail, Slowmotion and BulletFreezeRemove Pickups

Also refactored Extinguisher to remove particles from the end (still wonky though)
This commit is contained in:
2022-04-19 23:21:03 +02:00
parent e2511e2d53
commit 095fc0742b
19 changed files with 5467 additions and 45 deletions

View File

@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletFreezeRemove : Pickup
{
public ParticleSystem freezeParticles;
// Start is called before the first frame update
void Start()
{
}
public override void OnPickup()
{
//hide renderer
GetComponent<MeshRenderer>().enabled = false;
GetComponent<Collider>().enabled = false;
Debug.Log("Start thingy");
//find all particles in the scene and freeze them
ParticleSystem[] particleSystems = FindObjectsOfType<ParticleSystem>();
foreach (ParticleSystem particleSystem in particleSystems)
{
//if root gameobject has no pattern component it's not a pattern
GameObject root = particleSystem.transform.root.gameObject;
if (!root.GetComponent<Pattern>())
{
return;
}
int particleCount = particleSystem.particleCount;
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleCount];
particleSystem.GetParticles(particles);
for (int i = 0; i < particleCount; i++)
{
particles[i].velocity = Vector3.zero;
}
particleSystem.SetParticles(particles, particleCount);
StartCoroutine(RemoveParticle(particles, particleCount, particleSystem));
}
}
//coroutine that takes a collection of particles and removes one at a time
IEnumerator RemoveParticle(ParticleSystem.Particle[] particles, int particleCount, ParticleSystem particleSystem)
{
//Remove all particles over a span of .5 seconds
for (int i = 0; i < particleCount; i++)
{
particles[i].remainingLifetime = 0.0f;
particleSystem.SetParticles(particles, particleCount);
//instantiate freeze particles at the position of the particle
Instantiate(freezeParticles, particles[i].position, Quaternion.identity);
yield return new WaitForSeconds(0.5f/particleCount);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6ca67d0a50f0bad4593ac6b57598a2c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,6 +4,7 @@ using UnityEngine;
public class Extinguisher : Pickup
{
public ParticleSystem extinguishEffect;
public Player player;
[SerializeField]
@@ -11,13 +12,38 @@ public class Extinguisher : Pickup
public override void OnPickup()
{
// we have to stop the particle system before making changes
ParticleSystem system = player.trail.GetComponent<ParticleSystem>();
system.Stop();
ParticleSystem particleSystem = player.trail.GetComponent<ParticleSystem>();
int particleCount = particleSystem.particleCount;
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[particleCount];
particleSystem.GetParticles(particles);
system.startLifetime *= amount;
for (int i = 0; i < particleCount; i++)
{
if (particles[i].remainingLifetime < particleSystem.main.startLifetime.constant * 0.5f)
{
particles[i].remainingLifetime = 0.0f;
}
//instantiate freeze particles at the position of the particle
}
particleSystem.SetParticles(particles, particleCount);
StartCoroutine(SpawnEffectsCoroutine(particles, particleCount, particleSystem));
}
IEnumerator SpawnEffectsCoroutine(ParticleSystem.Particle[] particles, int count, ParticleSystem system)
{
system.Play();
for (int i = 0; i < count; i+=20)
{
if (particles[i].remainingLifetime < system.main.startLifetime.constant * 0.5f)
{
//instantiate freeze particles at the position of the particle
Instantiate(extinguishEffect, particles[i].position, Quaternion.identity);
yield return null;
}
}
}
// Start is called before the first frame update

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoTrail : Pickup
{
private Player player;
public float noTrailDuration = 5f;
// Start is called before the first frame update
void Start()
{
player = GameObject.Find("Player").GetComponent<Player>();
}
public override void OnPickup()
{
player.trail.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (pickedUp)
{
noTrailDuration -= Time.deltaTime;
if (noTrailDuration <= 0)
{
player.trail.SetActive(true);
Destroy(gameObject);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 31ff5267abecebc4b85a296d075e48c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Slowmotion : Pickup
{
public float slowFactor = 0.5f;
public float slowDuration = 5f;
private bool isSlow = false;
public override void OnPickup()
{
Debug.Log("Slowmotion");
isSlow = true;
Time.timeScale = Time.timeScale * slowFactor;
}
// Update is called once per frame
void Update()
{
if (isSlow)
{
slowDuration -= Time.deltaTime * (1 / slowFactor);
if (slowDuration <= 0)
{
Time.timeScale = Time.timeScale * (1 / slowFactor);
Destroy(gameObject);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 22f3fb16216e9164eafc1c9945d5016d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: