- Home /
Question by
TheBandman · Dec 31, 2014 at 10:44 AM ·
2dmoving
I want my character to move up and down the y axis but pause its movement whenever I press mouseclick
void Update () {
if (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButton (0)) {
count += 0.02;
} else {
transform.position = new Vector3(transform.position.x, Mathf.Sin((float)((Time.deltaTime) * maxSpeed)) / 2, transform.position.z);
This is all I have so that my character moves up and down and it stops whenever I click, but when I release, the character resumes where it should've been if movement had continued and not from where it is.
Comment
I am pretty sure it has to do with Time.deltaTime since it keeps on increasing even when that part of the code is not running when you press space or mousebutton
Your answer
![](https://koobas.hobune.stream/wayback/20220613175214im_/https://answers.unity.com/themes/thub/images/avi.jpg)