using UnityEngine;
using System.Collections;
public class player : MonoBehaviour
{
CharacterController controller;
public Vector3 moveDirection = Vector3.zero;
public float moveSpeed = 5f;
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);
}
}
}
using UnityEngine;
using System.Collections;
//存入
public class GlobalSetting
{
private static GlobalSetting Instance;
public static float MouseSensitive = 150f;
public static float voice = 0.5f;
//确保该实例只有1个
public static GlobalSetting GetInstance()
{
if (Instance == null)
{
Instance = new GlobalSetting();
}
return Instance;
}
}