using UnityEngine;
using System.Collections;
public class player : MonoBehaviour
{
CharacterController controller;
public Vector3 moveDirection = Vector3.zero;
public float moveSpeed = 2f;
public float rotateSpeed;
public float x, fx, y, fy;
public float gravity = 200.0f;
// Use this for initialization
void Start()
{
controller = GetComponent<CharacterController>();
transform.eulerAngles = Vector3.zero;
}
// Update is called once per frame
void FixedUpdate()
{
rotateSpeed = GlobalSetting.MouseSensitive;
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis("Horizontal");
moveDirection = new Vector3(h, 0, v);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= moveSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
if (Input.GetMouseButton(1))
{
x -= Input.GetAxis("Mouse X") * rotateSpeed * Time.deltaTime;
y -= Input.GetAxis("Mouse Y") * rotateSpeed * Time.deltaTime;
fx = -x;
fy = -y;
transform.eulerAngles = new Vector3(fy, fx, 0);
}
}
}
漫游代码
最新推荐文章于 2024-06-30 08:47:45 发布