[Solved] Can i make a point light when i click on terrain?

What i actually need is a code for when i click on the GameObject or Terrain it create a Point Light on mouse position and destroy the last one created.

I`ve searched around there and found nothing about this. Can i have some orientation?

Thanks in advance.

Why create a new one and destroy the old one instead of just having a single object with a point light where you just update the Transform position?

Yeah works as well, but thats not the main problem. What im stuck on is on starting scripting.

Don`t know where to start for to create the point light and update to mouse position.

Something like this would, if attached to a GameObject that had a point light at its local origin, move the GameObject (and that point light) to a location that is clicked when the mouse is released.

function Update() {
   if (Input.GetMouseButtonUp (0)){
      // The user clicked
      var hit : RaycastHit;
      if (Physics.Raycast (camera.ScreenPointToRay(Input.mousePosition), hit)){
         // and they clicked on something, so move the light there
         transform.position = hit.point;
      }
   }
}

First, thanks for helping.

Second, i`ve done what u told me. Created a Empty Gameobject and then created a point light and put as a child of the Gameobject

Then i put the script into it, but i got the following error:

MissingComponentException: There is no 'Camera' attached to the "Ponto de Luz - Clique" game object, but a script is trying to access it.
You probably need to add a Camera to the game object "Ponto de Luz - Clique". Or your script needs to check if the component is attached before using it.

What im doing wrong? Sorry if its a newbie question, but im new at Javascript as well as Unity, but i`m learning =].

Thanks in advance.

No… I did something wrong there. I was originally thinking I would write it to attach to a camera. You just need to change “camera.ScreenPointToRay(Input.mousePosition)” to “Camera.main.ScreenPointToRay(Input.mousePosition)”

Thanks, it worked now. Nice to see people helping people here. [ ]'s