94 lines
2.4 KiB
C#
Raw Normal View History

using KinematicCharacterController.Examples;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace CustomUse {
public class MyCustomPlayer : MonoBehaviour
{
public MyCustomExampleCharacterCamera OrbitCamera;
public MyCharacterController Character;
public Transform CameraFollowPoint;
private const string MouseXInput = "Mouse X";
private const string MouseYInput = "Mouse Y";
private const string MouseScrollInput = "Mouse ScrollWheel";
private const string HorizontalInput = "Horizontal";
private const string VerticalInput = "Vertical";
private void Start()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OrbitCamera.SetFollowTransform(CameraFollowPoint);
//<2F><><EFBFBD>Խ<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD>ͷ<EFBFBD>ϰ<EFBFBD><CFB0><EFBFBD><EFBFBD><EFBFBD>
OrbitCamera.IgnoredColliders.Clear();
OrbitCamera.IgnoredColliders.AddRange(Character.GetComponentsInChildren<Collider>());
}
private void Update()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
KeyboardInput();
}
private void LateUpdate()
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
CameraInput();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public void KeyboardInput() {
PlayerCharacterInputs characterInputs = new PlayerCharacterInputs();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1>ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
characterInputs.MoveAxisForward = Input.GetAxisRaw(VerticalInput);
characterInputs.MoveAxisRight = Input.GetAxisRaw(HorizontalInput);
characterInputs.CameraRotation = OrbitCamera.Transform.rotation;
//<2F><><EFBFBD>̰<EFBFBD><CCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Character.SetInputs(ref characterInputs);
//Ӧ<>õ<EFBFBD><C3B5><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Character.SetInputs(ref characterInputs);
}
///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void CameraInput() {
//<2F><><EFBFBD><EFBFBD> xy
float mouseLookAxisUp = Input.GetAxisRaw(MouseYInput);
float mouseLookAxisRight = Input.GetAxisRaw(MouseXInput);
Vector3 lookInputVector = new Vector3(mouseLookAxisRight, mouseLookAxisUp, 0f);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WebGL<47>н<EFBFBD><D0BD>ã<EFBFBD><C3A3><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>ܻᵼ<DCBB><E1B5BC><EFBFBD><EFBFBD><EFBFBD>
float scrollInput = -Input.GetAxis(MouseScrollInput);
#if UNITY_WEBGL
scrollInput = 0f;
#endif
//Ӧ<>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
OrbitCamera.UpdateWithInput(Time.deltaTime, scrollInput, lookInputVector);
}
}
}