My problem has to do with lights.
I have a spotlight, and I would like the spotlight to be turned off when my character touches an object I have created.
The script I have is:
private var GotHit = false;
var TargetLight : Light;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Collide")
{
GotHit = true;
}
}
function Update ()
{
if(GotHit)
{
TargetLight.enabled = false;
}
}
For some reason, It doesn't work. I've checked my tags, and I've specified the object to be disabled.
Does anyone have a general script to be used on collision to disable another object?
Why are you splitting the logic across both functions? Why not just do:
function OnControllerColliderHit(hit: ControllerColliderHit) {
if(hit.gameObject.tag == "Collide") TargetLight.enabled = false;
}
If you do it that way, then you're reducing the number of things that could be going wrong.
Once you have an implementation that is simple like this, you can start debugging it. The first thing you could try would be to add a Debug.Log command, like this:
function OnControllerColliderHit(hit: ControllerColliderHit) {
Debug.Log("OnControllerColliderHit is executing!");
if(hit.gameObject.tag == "Collide") TargetLight.enabled = false;
}
When you run that script, you should see the message "OnControllerColliderHit is executing!" whenever you collide with anything. If you do, then we know that the problem is with the way that you're responding to collisions; while if you don't, then we know that the problem is that you're not being informed about collisions at all. That will help us narrow down the source of the problem.