- Home /
How do i make this script work more then once?
Hello i have this script to when clicked on the screen move camera, but it only works once how can i make it to work all the time?
#pragma strict
function Update ()
{
if (Input.GetMouseButton(0))
{
Camera.main.transform.position = Vector3(51,3,0);
}
}
It must be attached to something that is destroyed or disabled if it only works once
$$anonymous$$y point is that this script would work all the time. What is this script attached to?
Which is always visible, always enabled and never destroyed? I would have thought it would make more sense being attached to the Camera.
Hang on - you don't want it to only happen when you click the text do you? It isn't doing that at the moment.
Answer by torrente · Jun 13, 2012 at 11:32 PM
Looks to me like your logic here says to move the camera to the world space coordinates of (51,3,0). Once it is moved there, every button hit after that will again move it to the same location (51,3,0) so it looks like it is just running this one time. Once you are at (51,3,0) it will never look any different no matter how many calls to the code you make. If you want it to increment by 51 and 3, you would use Camera.main.transform.Translate(51,3,0). Make sure that you also multiply this by Time.deltaTime in order to slow it down a bit.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Mouse Pointer Transform.Position? 1 Answer
how to stop mouse going out of the screen ? 9 Answers
touch input 2 Answers
Can you pause unity playmode while mouse button is down? 2 Answers