Add Alot of stuff, Computer, repairStation, Whole game, Many things!

This commit is contained in:
2024-11-18 06:31:28 +01:00
parent 19b7964f83
commit a2091c3cf2
430 changed files with 55285 additions and 715 deletions

View File

@@ -5,8 +5,6 @@ using UnityEngine;
public class BasicCharacter : MonoBehaviour {
protected MovementBehaviour _movementBehaviour;
//Kinda not the best but it's fine for now
//TODO: Fix this, (ask teacher)
protected InteractionBehaviour _interactionBehaviour;
public InteractionBehaviour InteractionBehaviour {
get => _interactionBehaviour;

View File

@@ -43,7 +43,6 @@ public class InteractionBehaviour : MonoBehaviour, IObjectParentHolder {
RaycastHit hit;
Debug.DrawRay(origin, transform.forward * _interactionDistance, Color.red);
if (Physics.Raycast(origin, transform.forward, out hit, _interactionDistance, _interactionLayer)) {
// Debug.Log("Hitting something!");
GameObject hitObject = hit.transform.gameObject;
//Check if the object has a component that has the IInteractable interface
if (hitObject.TryGetComponent(out IInteractable interactable)) {
@@ -64,7 +63,7 @@ public class InteractionBehaviour : MonoBehaviour, IObjectParentHolder {
public void Interact() {
if (_lastInteractedObject == null) return;
if (_lastInteractedObject.TryGetComponent(out IInteractable interactable)) {
interactable.Interact();
interactable.Interact(this);
}
}

View File

@@ -2,74 +2,69 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementBehaviour : MonoBehaviour {
[SerializeField]
private float _movementSpeed = 10.0f;
[SerializeField]
private float _rotationSpeed = 10.0f;
public class MovementBehaviour : MonoBehaviour {
[SerializeField] private float _movementSpeed = 10.0f;
[SerializeField] private float _rotationSpeed = 10.0f;
[Header("Player")] [SerializeField] private float _playerHeight = 1.0f;
[SerializeField] private float _playerRadius = 0.5f;
[Header("Player")]
[SerializeField]
private float _playerHeight = 1.0f;
[SerializeField]
private float _playerRadius = 0.5f;
private Vector3 _desiredMovementDirection = Vector3.zero;
public Vector3 desiredMovementDirection
{
public Vector3 desiredMovementDirection {
get => _desiredMovementDirection;
set => _desiredMovementDirection = value;
}
public Vector3 desiredLookDirection
{
public Vector3 desiredLookDirection {
get => _desiredMovementDirection;
set => _desiredMovementDirection = value;
}
private void Update()
{
private void Update() {
HandleMovement();
HandleRotation();
}
private void HandleMovement()
{
private void HandleMovement() {
Vector3 movement = _desiredMovementDirection.normalized;
float moveDistance = _movementSpeed * Time.deltaTime;
bool canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * _playerHeight,
_playerRadius, movement, moveDistance);
if (!canMove) {
// Cannot goto movedir
Vector3 moveX = new Vector3(movement.x, 0, 0);
canMove = movement.x != 0 && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * _playerHeight,
canMove = movement.x != 0 && !Physics.CapsuleCast(transform.position,
transform.position + Vector3.up * _playerHeight,
_playerRadius, moveX, moveDistance);
if (canMove) {
movement = moveX;
} else {
}
else {
Vector3 moveZ = new Vector3(0, 0, movement.z);
canMove = movement.z != 0 && !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * _playerHeight,
canMove = movement.z != 0 && !Physics.CapsuleCast(transform.position,
transform.position + Vector3.up * _playerHeight,
_playerRadius, moveZ, moveDistance);
if (canMove) {
movement = moveZ;
}
}
}
if (canMove) {
// movement *= _movementSpeed * Time.deltaTime;
transform.position += movement * moveDistance;
}
}
}
private void HandleRotation() {
transform.forward =
Vector3.Slerp(transform.forward, _desiredMovementDirection, Time.deltaTime * _rotationSpeed);
}
}
}

View File

@@ -49,7 +49,7 @@ public class PlayerController : BasicCharacter {
Debug.LogError("No HUDManager found");
return;
}
if (!_hudManager.isUiOpen) {
if (!_hudManager.IsUiOpen) {
HandleMovementInput();
HandleInteraction();
}