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?
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;
}
}
}
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 =].
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)”