I
I
Ilya Famin2021-05-02 17:54:41
C++ / C#
Ilya Famin, 2021-05-02 17:54:41

How to move the camera while holding down any key?

Here's what I got

private void Update() {
        pos = player.position;
        pos.z = -10f;
        transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime);
        if (Input.GetKey(KeyCode.S)) {
            bias = new Vector3(pos.x, pos.y - 5);
            transform.position = Vector3.Lerp(transform.position, bias, Time.deltaTime);
        }
    }

It is only necessary that the camera does not constantly mix by 5 units, but moves once and that's it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CHIDWI, 2021-05-06
@CHIDWI

You can use Input.GetKeyDown("s"), this function is called only once when the button is clicked. Or it is possible to cut off some bool flag thread.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question