so i have this project due for school were we’re learning unity but I’m having a heck of a time trying to implement a particle system. i tried making a class that would control the attributes, then spawn a game object in update so the particles will keep coming out, then afterwords was gonna add gravity and start detecting collisions but I haven’t even gotten to that part yet. And for this i can’t use the particle emitter or rigid bodies.
heres what i’ve most recently been working with, it seems to spawn one every second but i can’t move them for the life of me and i feel like something is fundamentally wrong with how I’m going about this.
using UnityEngine;
using System.Collections;
public class particle : MonoBehaviour {
public float age = 2;
public float ageMax = 6;
public Vector3 velocity;
public Vector3 position = new Vector3(0,6,0);
public float mass = 1;
void Start() {
}
}
public float lastSpawn=0;
void Update() {
if (Time.time > lastSpawn + 1.0) {
GameObject particley = GameObject.CreatePrimitive (PrimitiveType.Sphere);
particley.transform.localScale = new Vector3(0.2f,0.2f,0.2f);
particley.transform.position = new Vector3(0,4.5f,0);
lastSpawn = Time.time;
float grav = 20;
float i;
bool die = false;
for (i = 0;i < 20; i++) {
velocity.x = Random.Range(0,3);
velocity.y = Random.Range(0,3);
velocity.z = Random.Range(0,3);
if (i == 19) {
die = true;
}
}
if (die == true) {
Destroy(particley);
die = false;
}
}
}
}
I’m putting this script on a cube that will act like its just forever pouring little spheres out of it, eventually I would add some side direction to it so they go back and forth. Also i’ve tried just doing a constant translate down on particley but that didn’t work either. Any feedback is appreciated before i pull my hair out over this, thanks!