Activate when mouse klick object

I’m trying to make button that activates and deactivates light.

I have tried following script but it doesn’t seem to work.

using UnityEngine;
using System.Collections;

public class ToggleLightButton : MonoBehaviour
{
    public Light Light;

	void OnMouseDown ()
    {
        Light.enabled = true;
    }
}

create a public function

public void LightOn()
{
Light.enabled = true;
}

Now drag the script on the light or anywhere. Then drag the gameobject in the buttons onClick event, and choose the function.

Should work.

If its a 3d object you need to use raycast i believe.