As it says on the title. I have a game object acting as a pseudo-particle. As it moves it generates a trail, as I want it to. However I have a script attached that destroys the game object after a certain amount of time. When the pseudo-particle dies it destroys the entire object, including the trail renderer. What I want to happen is that the object should appear to abruptly stop in place with the trail renderer continuing along until it reaches where the object stops, then the pseudo-particle dies.
Here’s what the Kill code looks like in the Update function (using C# code)
if (kill > Random.Range (100,300))
{
Destroy (gameObject);
}
Another solution would be to make both the TrailRenderer and this object a child of a common parent (empty game object). Movement code would go on the parent.
Neurological got it right on the “stop object programatically” part. However as i’ve tried before, simply adding this line to the Kill function…:
transform.Translate (Vector3.up * speed * Time.deltaTime);
…doesn’t do anything. I instead tied the movement to a Vector3 Variable which is assigned the (Vector3.up * speed * Time.deltaTime) on the Start function. When the object is “killed” it is reassigned to Vector3.zero and the DestroyObject has a delay of 5
The code looks like this for anyone who comes across this question and wants to know how I did it (not the complete code, but the parts unnecessary to the functioning of what I described were omitted)
using UnityEngine;
using System.Collections;
public class OrthoMove : MonoBehaviour {
public float speed = 3;
private Vector3 mover = new Vector3 (); //the variable that moves my pseudo-particle
private float kill = 0;
// initialization
void Awake () {
mover = (Vector3.up * speed * Time.deltaTime);
}
void Update () {
transform.Translate (mover);
kill = kill + 1; //kill timer. I know it should be 'kill++;' but I never found it to be reliable.
if (kill > Random.Range (100,3000))
{
mover = Vector3.zero; //forces pseudo-particle to stop
Destroy (gameObject, 5); //killswitch
}
}
}