I’m making a space sim, and when the ship activates it’s boosters, a trail renderer has to appear and create a trail as it boosts, and when the player turns off boost, the trail renderer disappears. Right now, when the player boosts, in the hierarchy, it says that the trail are there, but visibly, I can’t see them on the ship. The trails don’t destroy themselves when the boost if off either. Here’s the set up
On each wing, an empty game object is there. To the game objects I added the trail script:
var trail : GameObject;
function Update ()
{
if(Input.GetKeyDown ("space")){
Instantiate(trail, transform.position, transform.rotation);
}
if(Input.GetKeyUp ("space")){
Destroy(transform.trail);
}
}
When you hit space, the trail supposedly instantiates (btw, I’m using a trail renderer to make the trail) but nothing happens. Plus, the trail doesn’t destroy itself like I wrote in the script. There are no errors, so the syntax is correct. I’m not sure why it’s doing this. Help would be appreciated. Thanks in advance.
Update
The questions has almost been answered thankfully to stopsecret but it hasn’t been completely answered. Now, using stopsecret’s script, I need to make it destroy when you let go of the space bar. I’m not sure how to fix that. Thanks in advance.
Update
I finally figured how to destroy the trail, but the problem is, once the trail is destroyed, you can’t instantiate it again, so when I boost, the trail appears, but when I boost again the trail isn’t there. So I need to figure out a way to destroy the trail when not boosting, and have it continually come up whenever I boost. Here’s the script:
var trail : GameObject;
function Update ()
{
if(Input.GetKeyDown ("space")){
var trailTransform = Instantiate(trail, transform.position, transform.rotation);
trailTransform.transform.parent = transform;
}
if(Input.GetKeyUp ("space")){
Destroy(gameObject);
}
In the script, once the gameObject is destroyed, it doesn't instantiate again. How would I solve this?