简体   繁体   中英

How do I rotate an object while the key is pressed?

Here's my code:

public Transform Dummy;
public Transform Sphere;


void Start () {
    Sphere.SetParent(Dummy);
}

// Update is called once per frame
void Update () {
    if (Input.GetKeyDown(KeyCode.Space))
        Dummy.rotation = Quaternion.RotateTowards(transform.rotation, new Quaternion(1, 1, 1, 0), (float)20 * Time.deltaTime);
}

The problem is that it rotates only once when the Space key is pressed, so I need to press it many times, which is bad. I need to rotate the Dummy while the space key is pressed.

如果要连续旋转,则应使用GetKey ,而不要使用GetKeyDown

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM