66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MouseOrbit : MonoBehaviour
|
|
{
|
|
public bool ShieldingOperation;
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 加速
|
|
/// </summary>
|
|
float accelerate;
|
|
public float speed = 50;
|
|
|
|
void Update()
|
|
{
|
|
if (ShieldingOperation) return;
|
|
if (transform.position.y <= 1f) transform.position = new Vector3(transform.position.x,1f, transform.position.z);
|
|
if (Input.GetMouseButton(0))//UtilityInput.HoldRightMouse)
|
|
{
|
|
float x = Input.GetAxis("Mouse X");
|
|
float y = Input.GetAxis("Mouse Y");
|
|
transform.Rotate(new Vector3(-y, x) * 1.8f);
|
|
|
|
Vector3 v = transform.localEulerAngles;
|
|
transform.localEulerAngles = new Vector3(v.x, v.y, 0);
|
|
}
|
|
|
|
if (Input.GetMouseButton(2))
|
|
{
|
|
float x = Input.GetAxis("Mouse X");
|
|
float y = Input.GetAxis("Mouse Y");
|
|
transform.Translate(new Vector3(-x*1.2f, -y*1.2f));
|
|
}else if (Input.GetKey(KeyCode.Q))
|
|
{
|
|
float y = Time.deltaTime * 5;
|
|
transform.Translate(new Vector3(0, -y));
|
|
}
|
|
else if (Input.GetKey(KeyCode.E))
|
|
{
|
|
float y = -Time.deltaTime * 5;
|
|
transform.Translate(new Vector3(0, -y));
|
|
}
|
|
if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
|
//UtilityInput.Horizontal != 0 || UtilityInput.Vertical != 0)
|
|
{
|
|
if (accelerate < 10)
|
|
accelerate += Time.deltaTime * 5;
|
|
}
|
|
else
|
|
{
|
|
accelerate -= Time.deltaTime * 5;
|
|
}
|
|
accelerate = Mathf.Clamp(accelerate, 0, 10);
|
|
transform.Translate(Dirction);
|
|
if (Dirction.Equals(Vector3.zero)) transform.Translate(Vector3.forward * Input.GetAxis("Mouse ScrollWheel") * 10);
|
|
}
|
|
|
|
|
|
public Vector3 Dirction => new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * Time.deltaTime * accelerate * (Input .GetKey(KeyCode.LeftShift) ? 20 : 010);
|
|
|
|
} |