How do I toggle the trail renderer for my ski game

So, I am aware of the “GetComponent(TrailRenderer).enabled = true;” script function, but when I switch this to false in my move script below - it turns off the entire trail. I want to be able to start and stop it when my skier gets airborne.

Here is my script below… I have tried popping it into my script as per below when the skier is on the ground only, but when I disable when in the air, the whole track/trail dissappears from my scene. Any ideas?

var speed : float = 10.0;
var jumpSpeed : float = 8.0;
var gravity : float = 10.0;
private var moveDirection : Vector3 = Vector3.zero;
var tracker: Transform;
var rotateSpeed = 3.0;

function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis (“Vertical”);
controller.SimpleMove(forward * curSpeed);

var hit1: RaycastHit;
var hit2: RaycastHit;

if (Physics.Raycast(tracker.position, -Vector3.up, hit1)) {
if (Physics.Raycast(tracker.TransformPoint(Vector3.forward * 0.1), -Vector3.up, hit2)) {
transform.rotation = Quaternion.LookRotation(hit2.point - hit1.point, hit1.normal);
}
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis(“Horizontal”), 0,
Input.GetAxis(“Vertical”));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;

gameObject.GetComponent(ParticleEmitter).emit= true; //tell the emitter to start
GetComponent(TrailRenderer).enabled = true; // this isn’t working
if (Input.GetButton (“Jump”)) {
moveDirection.y = jumpSpeed;
}
}
else {
gameObject.GetComponent(ParticleEmitter).emit= false; //tell the emitter to stop.
GetComponent(TrailRenderer).enabled = false; // this switches off the trail for the whole scene, not just when skier is in the air

}

// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}

}
function FixedUpdate () {
rigidbody.AddForce (-Vector3.up * 10);

}
@script RequireComponent(CharacterController)

You probably could unattach the trail renderer, then when grounded again, create a copy. That would be quite hard, I suspect, and render-heavy. That’s just my idea - you could give it a shot. But I don’t know if it would work perfectly.

Honestly though, I’m just guessing.

Edit: you could comment out the enabled = false line. Again, just a suggestion - but the emmiter.emit = false looks like it might do what you’re thinking of.

That’s not really possible with the built-in trail renderer, or even the line renderer. You will need to create your own procedural mesh, which allows for disconnected vertices.

Look at Yoggy’s time based trail renderer or the procedural example project for inspiration.

There are some workarounds to pause Unity TrailRenderers. I have notes on a duplicate thread here:

Congratulations Kevin.

You dug up two super old threads.

/high five