Unity turning light of via script problem

Simply turning off a light via a colision with a button and on collison with another turning back on… However it’s not working. The light turns of fine, but does nto want to turn back on… annoying.

The code uyou see below is an evolution of a previous answer

the light script:

private var on = false;

function Start(){
	var someScript1 : lightingswitchScript;
	someScript1 = gameObject.GetComponent("lightingswitchScript");

	var someScript2 : lightingswitchScript2;
	someScript2 = gameObject.GetComponent("lightingswitchScript2");
}

function Update () {
    if (lightingswitchScript.lighttouch == true){
    lightoff();
    }
    if (lightingswitchScript2.lighttouchh == true){
    lighton();
    }
}

function lightoff (){
    if (lightingswitchScript.lighttouch == true){
    if(on == false){
		light.intensity =0;
			on = false;
			}
			else {
				light.intensity =2;
				on = true;
			}
		}
	}

function lighton (){
	if (lightingswitchScript.lighttouch == false){
				on= true;
	if (on == true){
			light.intensity = 2;
			}
			else {
    				light.intensity =0;    
			on = false;    
			}    
		}  
	}

Any ideas are greatly appreciated.

NOTE: this is new code.

Pay attention: OnTriggerEnter needs at least one rigidbody among the two colliders. Is that the problem?

–

nope, player is a rigidbody, so it's fine i think!

–

Is your debug log "hit" showing?

–

yep! but i'll alter the first post as changed the code methology

–

Watch out, you've written lightingswitchScript2.lighttouchh with double final "h"! I know that's not the main problem, but I'm just letting you know.

–

1 Answer

1

ot try this:

Light myLight = ylight.GetComponent("Light");

In fact, “Light” is a component that you have to extract from a certain object, and not an object itself.

not quite, I've started using: getComponent(Light).enabled = true; Will see if i can figure it out

–

OK, let us know!

–