Pickup a flashlight doesnt works. Need help please
The function I was trying to do with this javascript: When I go in front of a flashlight model (simple Cube) with a fps controller and push "e": the cube/flashlight model disappears and my fps controller gets a spotlight/flashlight (you can turn the spotlight on/off with "e" to). I wanted to do that but here are the results of my script (from a youtuber): When I go in front of the flashlight model with the fps controller and push "e": the cube/flashlight model disappears and my fps controller gets a spotlight/flashlight but this spotlight disappears after a second too. I need help please.
pragma strict
var thisModel : GameObject; var myLight : Light;
private var getLight : boolean = false;
function Start () { myLight.GetComponent.().enabled = false; }
function Update () { var fwd = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;
if(Physics.Raycast(transform.position, fwd, hit))
{
if(hit.distance <= 5.0 && hit.collider.gameObject.tag == "PickUp")
{
getLight = true;
if(Input.GetKeyDown("e"))
{
Destroy(thisModel);
myLight.GetComponent.<Light>().enabled = true;
}
}
else
{
getLight = true;
myLight.GetComponent.<Light>().enabled = false;
}
}
}
Your answer