- Home /
Particle Emitting Speed Through Script
I have a JS which I try to change the velocity the particles are emitted. (I included full script for you to understand better)
#pragma strict
var engine: ParticleSystem;
var thrust: float;
var thrustRate: float;
var startThrust: float;
var fuel: float;
var F9: GameObject;
function Start () {
engine = GetComponent.<ParticleSystem>();
thrust = startThrust;
fuel = 70;
}
function Update () {
if(fuel > 0){
if(Input.GetKey(KeyCode.LeftShift)){
if(100 > thrust){
thrust = thrust + thrustRate;
}
}
if(Input.GetKey(KeyCode.LeftControl)){
if(thrust > 0){
thrust = thrust - thrustRate;
}
}
fuel = fuel - (thrust * 0.000001);
F9.GetComponent.<ParticleSystem>().Particle.velocity = thrust;
}
}
The problem is this part: F9.GetComponent.().Particle.velocity = thrust;
Console tells me "An instance of type 'UnityEngine.ParticleSystem.Particle' is required to access non static member 'velocity'.
Like I said, I want the particles go faster as I increase "thrust".
(If you ask why do I have sth called "engine", it is bc I tried to use it as engine.Particles.velocity but it didn't work)
Answer by Soraphis · Apr 23, 2016 at 04:00 PM
ParticleSystem.Particle is a inner class. what you want to adress is F9.GetComponent.<ParticleSystem>().startSpeed
or velocityOverLifetime
you can see all the variables here: http://docs.unity3d.com/ScriptReference/ParticleSystem.html