- Home /
OnMouseDown carry out whole function problem
hi Im not an expert on Javascript and could really do with some help please.
Im making a flying game and want to automate some of the movements to give the feel of being flown to different locations.
I have GUI buttons set up and the following Javascript is attached to each button which in turn is parented to the camera with a target and speed set.
The problem I am having is that when you press the GUI button the camera only moves within the OnMouseDown time (less than a second) so if you set the time to say 0.5 the camera will jump to the location but I need a flowing motion. How do i set the GUI button to carry out all the motion and not as just a bit of it when it is active?
Javascript =
var normaltex : Texture2D;
var hovertex : Texture2D;
var target : Transform;
var smoothTime = 0.3;
private var velocity = Vector3.zero;
function OnMouseEnter(){
guiTexture.texture = hovertex;
} function OnMouseExit(){
guiTexture.texture = normaltex;
} function OnMouseDown(){
var targetPosition : Vector3 = target.TransformPoint(Vector3(0, 5, -30));
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, velocity, smoothTime);}
Thanks in advance
J
Your answer
![](https://koobas.hobune.stream/wayback/20220613091404im_/https://answers.unity.com/themes/thub/images/avi.jpg)