add basic inventory, fading walls
This commit is contained in:
@@ -11,11 +11,14 @@ public class PlayerController : MonoBehaviour
|
||||
bool isDigging = false;
|
||||
|
||||
Interactable nearestInteractable;
|
||||
private CharacterController characterController;
|
||||
private Vector3 moveDir;
|
||||
private float gravity = 10;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
characterController = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -24,17 +27,30 @@ void Update()
|
||||
if (!isDigging)
|
||||
{
|
||||
RotatePlayerTowardMouse();
|
||||
Walk();
|
||||
TryInteract();
|
||||
}
|
||||
|
||||
|
||||
Walk();
|
||||
DigDetector();
|
||||
}
|
||||
|
||||
void Walk()
|
||||
{
|
||||
transform.position += DougBody.transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
|
||||
transform.position += DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
|
||||
moveDir = Vector3.zero;
|
||||
|
||||
if (!characterController.isGrounded)
|
||||
{
|
||||
moveDir.y -= gravity * Time.deltaTime;
|
||||
}
|
||||
|
||||
if (!isDigging)
|
||||
{
|
||||
Vector3 verticalMovement = DougBody.transform.forward * Input.GetAxis("Vertical") * walkSpeed * Time.deltaTime;
|
||||
Vector3 horizontalMovement = DougBody.transform.right * Input.GetAxis("Horizontal") * walkSpeed * Time.deltaTime;
|
||||
moveDir += verticalMovement + horizontalMovement;
|
||||
}
|
||||
|
||||
characterController.Move(moveDir);
|
||||
}
|
||||
|
||||
void DigDetector()
|
||||
@@ -93,7 +109,7 @@ private void OnTriggerExit(Collider other)
|
||||
Interactable interactable = other.GetComponent<Interactable>();
|
||||
|
||||
// store nearest interactable if it exists
|
||||
if (interactable != null)
|
||||
if (interactable != null && nearestInteractable != null)
|
||||
{
|
||||
nearestInteractable.MoveOutsideRange();
|
||||
nearestInteractable = null;
|
||||
|
||||
Reference in New Issue
Block a user