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)