#pragma strict
var bSpeed : float = 1.0;
var time : float;
private var startTime : float;
function Start () {
}
function Update () {
if(Input.GetMouseButtonDown(0)){
Slide();}
}
function Slide () {
transform.Translate(Vector3.forward * Time.deltaTime * bSpeed);
yield WaitForSeconds (time);
transform.Translate(Vector3.forward * Time.deltaTime * -bSpeed);
}
I created a simple script that’s used for moving an object back and forth when the mouse is clicked(used for the bolt/slide on guns), but for some reason it’s fairly unstable. The slide never moves back and forth the same amount, often resulting in the object displacing itself on the forward axis. I only want it to move so far back then return to the default position, but it often time varies in the locations it sets itself to. Is it simply Time.deltaTime that’s messing with it? Keeping to my original script would be great, thanks!