- Home /
How to use collision to enable light?
I have tried a few codes already on the topic, usually resulting in errors and broken scripts that were not able to be attached to the game objects. I'd simply like to have a sphere's collision detect the player when they walk into this objects range. Thus enabling the parented light on. I am new to scripts my apologies. Can you please show an example of the script? I am not sure of how to have everything setup properly for the script to work. To note, I wish to activate the lights only by player proximity to the lights. The characters death would deactivate the lights as well as enemies passing by, but one thing at a time for now.
var Orb : Light;
function OnCollisionEnter(hit : Collision)
{
if (hit.gameObject.name == "Player")
{
Orb.enabled = true;
}
}
....its the start of my code, I'm not sure how to place it properly in the script editor.
r u using a character controller as a player or any thing else
Yep, I am using the First Person Controller from the standard assets.
Answer by yogee · Oct 22, 2013 at 06:10 AM
then use this function instead of ur's ,
function OnControllerColliderHit (hit : ControllerColliderHit){
}
but the script is for First Person Controller mind it,
Ah the small details. Thank you although I have encountered an error when placing the script onto the object. "can't add script / compilation has not finished".. I'm sure there's an answer to that on this forum already.
Cheers.