Spotlight

Hi. I want switch the spotlight on and off with right-mouse click.but i can’t. Help me please.

Can you show your code?

look into, the reference manual, unity manual and scripting guide before asking a question, and there is a search engine called google you can use. :slight_smile:

	public Light Spotlight;
	
	void Start ()
	{
		Spotlight.enabled = false;
	}

	// Update is called once per frame
	void Update () 
	{
		if (Input.GetKeyDown(KeyCode.Mouse1))
		{
			Spotlight.enabled =! Spotlight.enabled;
		}
	}
}

This is JavaScript but it should work for what you are asking for:

var Off = false;
var spotlight : GameObject;

function Update () {
	if(Input.GetButtonDown("Fire1")){
		if(Off){
			Off = false;
		}
		else{
			Off = true;
		}
	}
		
	if(Off){
		spotlight.gameObject.SetActiveRecursively(false);
			
	}
	else{
		spotlight.gameObject.SetActiveRecursively(true);
	}
}

I use this in one of my project as a wepon holster thing :stuck_out_tongue:
Put it on the player!