studycase2
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
@@ -7,28 +8,50 @@ public class ThirdCharacterController : MonoBehaviour
|
||||
public Animator animator;
|
||||
public Transform forward;
|
||||
public Transform model;
|
||||
public List<GameObject> hitItems = new List<GameObject>();
|
||||
public Cinemachine.CinemachineVirtualCamera vCam;
|
||||
public float moveSpeed = 5f;
|
||||
public float jumpSpeed = 2f;
|
||||
public float turnSpeed = 10f;
|
||||
public float gravity = 10f;
|
||||
public float maxDistance = 100f;
|
||||
public LayerMask layerMask;
|
||||
public bool areaPick;
|
||||
Vector3 moveDir;
|
||||
Vector2 moveInput;
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
moveDir = new Vector3 (moveInput.x, moveDir.y, moveInput.y);
|
||||
Move();
|
||||
}
|
||||
public void CheckRayHit()
|
||||
{
|
||||
Ray ray = new Ray(vCam.transform.position, vCam.transform.forward);
|
||||
RaycastHit raycastHit;
|
||||
if(Physics.Raycast(ray,out raycastHit, maxDistance, layerMask))
|
||||
{
|
||||
Debug.Log($"CheckRayHit:{raycastHit.collider.gameObject.name}");
|
||||
hitItems[0] = raycastHit.collider.gameObject;
|
||||
}
|
||||
}
|
||||
public void Move()
|
||||
{
|
||||
moveDir = new Vector3(moveInput.x, moveDir.y, moveInput.y);
|
||||
forward.eulerAngles = new Vector3(0, vCam.transform.eulerAngles.y, 0);
|
||||
moveDir = forward.TransformDirection(moveDir);
|
||||
if (moveInput != Vector2.zero)
|
||||
{
|
||||
animator.SetBool("Move", true);
|
||||
animator?.SetBool("Move", true);
|
||||
Quaternion target = Quaternion.LookRotation(new Vector3(moveDir.x, 0, moveDir.z));
|
||||
model.rotation = Quaternion.Slerp(model.rotation, target, turnSpeed*Time.deltaTime);
|
||||
}
|
||||
else animator.SetBool("Move", false);
|
||||
model.rotation = Quaternion.Slerp(model.rotation, target, turnSpeed * Time.deltaTime);
|
||||
}
|
||||
else animator?.SetBool("Move", false);
|
||||
if (!characterController.isGrounded)
|
||||
moveDir.y -= gravity * Time.deltaTime;
|
||||
characterController.Move(moveDir*moveSpeed*Time.deltaTime);
|
||||
characterController.Move(moveDir * moveSpeed * Time.deltaTime);
|
||||
}
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
@@ -43,4 +66,8 @@ public class ThirdCharacterController : MonoBehaviour
|
||||
moveDir.y = jumpSpeed;
|
||||
}
|
||||
}
|
||||
public void OnPickUp(InputAction.CallbackContext context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user