1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-29 03:24:30 +00:00
gravity-fusion/Assets/Components/Emitter.cs

34 lines
1.1 KiB
C#
Raw Normal View History

2019-10-06 13:04:50 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Particle))]
public class Emitter : MonoBehaviour
{
2019-10-06 15:44:41 +00:00
public float emissionPeriod;
public int emissionQuantity;
2019-10-06 13:04:50 +00:00
protected Particle particle;
protected void Awake() {
particle = GetComponent<Particle>();
}
protected void Start() {
2019-10-06 15:44:41 +00:00
Invoke("Emit", emissionPeriod);
2019-10-06 13:04:50 +00:00
}
protected void Emit() {
2019-10-06 15:44:41 +00:00
Invoke("Emit", emissionPeriod);
if(particle.Tier < 2) return;
2019-10-06 17:04:47 +00:00
if(particle.Tier <= particle.gameController.maxTierPresent - 4) return;
2019-10-06 15:44:41 +00:00
for(int i = 0; i < emissionQuantity; i++) {
GameObject newObject = Instantiate(particle.ParticlePrefab, transform.position, Quaternion.identity);
Particle newParticle = newObject.GetComponent<Particle>();
newParticle.Tier = particle.Tier - 2;
Vector3 direction = new Vector3(Mathf.Cos(Mathf.PI * i * 2 / emissionQuantity), Mathf.Sin(Mathf.PI * i / emissionQuantity), 0).normalized;
2019-10-07 20:02:46 +00:00
newParticle.rigidbody.AddForce(direction * 0.01f);
2019-10-06 15:44:41 +00:00
}
2019-10-06 13:04:50 +00:00
}
}