抬头看我的性格向前移动我团结

问题描述 投票:0回答:0

我正在统一使用这个运动代码和一个盒子对撞机(我是一个初学者)

public class Movement : MonoBehaviour
 {
     public float speed = 10.0f;
 
     void Update()
     {
 
         float horizontalInput = Input.GetAxis("Horizontal");
         float verticalInput = Input.GetAxis("Vertical");
 
         transform.Translate(new Vector3(horizontalInput, 0, verticalInput) * Time.deltaTime * speed);
 
  

还有这个 mouselook 代码

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Mouselook : MonoBehaviour
 {
     public float sensitivity = 100.0f;
     public float clampAngle = 80.0f;
 
     private float rotX = 0.0f;
     private float rotY = 0.0f;
 
     void Start()
     {
         Vector3 rot = transform.localRotation.eulerAngles;
         rotX = rot.x;
         rotY = rot.y;
         Cursor.lockState = CursorLockMode.Locked;
         Cursor.visible = false;
     }
 
     void Update()
     {
         float mouseX = Input.GetAxis("Mouse X");
         float mouseY = -Input.GetAxis("Mouse Y");
 
         rotX += mouseY * sensitivity * Time.deltaTime;
         rotY += mouseX * sensitivity * Time.deltaTime;
 
         rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);
 
         Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
         transform.localRotation = localRotation;
     }
 }

我尝试制作不同的移动代码,我希望它能让我在统一益智游戏中使用 wasd 移动。

c# unity3d
© www.soinside.com 2019 - 2024. All rights reserved.