📜  如何在统一 3D 中使用键盘移动对象 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:05.504000             🧑  作者: Mango

代码示例1
public class realguymoves : MonoBehaviour //the class of object
{
    //movement
    float speed;

    float horizontal;
    float vertical;
    Vector3 moveDirecion;
    float drag;



    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontal = Input.GetAxisRaw("Horizontal"); //getting the horizontal axis of the object
        vertical = Input.GetAxisRaw("Vertical"); //getting the vectical axis of the object

        moveDirecion = transform.forward * vertical + transform.right * horizontal;
    }