90 lines
2.2 KiB
C#
90 lines
2.2 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.AI;
|
|||
|
|
|
|||
|
|
public class KeyController : BaseController
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform
|
|||
|
|
/// <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD>ǰ<EFBFBD>ű<EFBFBD><C5B1><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
[Tooltip("<22><><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>Transform<72><6D>Ĭ<EFBFBD><C4AC>Ϊ<EFBFBD><CEAA>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>")]
|
|||
|
|
public Transform tran;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩
|
|||
|
|
/// </summary>
|
|||
|
|
[Tooltip("<22>ƶ<EFBFBD><C6B6>ٶȣ<D9B6><C8A3><EFBFBD>/<2F>룩")]
|
|||
|
|
public float moveSpeed = 5;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩
|
|||
|
|
/// </summary>
|
|||
|
|
[Tooltip("<22><>ת<EFBFBD>ٶȣ<D9B6><C8A3>Ƕ<EFBFBD>/<2F>룩")]
|
|||
|
|
public float rotateSpeed = 10;
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ƶ<EFBFBD>ʱ<EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public bool AutoResetView = true;
|
|||
|
|
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
if (tran == null)
|
|||
|
|
tran = transform;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
float h, v;
|
|||
|
|
|
|||
|
|
void Update()
|
|||
|
|
{
|
|||
|
|
// Debug.Log(IsKeyOnControl);
|
|||
|
|
if (CanControl)
|
|||
|
|
{
|
|||
|
|
if (Input.GetKey(KeyCode.Q))
|
|||
|
|
{
|
|||
|
|
tran.Rotate(Vector3.down * rotateSpeed * Time.deltaTime); // <20><><EFBFBD><EFBFBD>ת
|
|||
|
|
}
|
|||
|
|
if (Input.GetKey(KeyCode.E))
|
|||
|
|
{
|
|||
|
|
tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime); // <20><><EFBFBD><EFBFBD>ת
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
h = Input.GetAxis("Horizontal"); // <20><>ȡˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD>
|
|||
|
|
v = Input.GetAxis("Vertical"); // <20><>ȡ<EFBFBD><C8A1>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
if (h != 0 || v != 0)
|
|||
|
|
{
|
|||
|
|
ControllWithKey(h, v);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
IsKeyOnControl = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Vector3 tmp;
|
|||
|
|
/// <summary>
|
|||
|
|
/// ʹ<>ü<EFBFBD><C3BC>̿<EFBFBD><CCBF>ƶ<EFBFBD><C6B6><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="h">ˮƽƫ<C6BD><C6AB><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <param name="v"><3E><>ֱƫ<D6B1><C6AB><EFBFBD><EFBFBD></param>
|
|||
|
|
void ControllWithKey(float h, float v)
|
|||
|
|
{
|
|||
|
|
IsKeyOnControl = true;
|
|||
|
|
|
|||
|
|
//tran.position += tran.forward * moveSpeed * Time.deltaTime * v; // <20>ƶ<EFBFBD>
|
|||
|
|
//tran.Rotate(Vector3.up * rotateSpeed * Time.deltaTime * h); // <20><>ת
|
|||
|
|
|
|||
|
|
tmp.x = h;
|
|||
|
|
tmp.z = v;
|
|||
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|||
|
|
{
|
|||
|
|
tran.Translate(tmp * moveSpeed * Time.deltaTime * 4f);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
tran.Translate(tmp * moveSpeed * Time.deltaTime);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|