Skip to content

Commit

Permalink
Reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Fripe070 committed Jun 7, 2023
1 parent e5bf02b commit 3d7b362
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 194 deletions.
22 changes: 7 additions & 15 deletions Assets/Scripts/FruitFly/Enemy.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour, IDamageable
{
public float health = 100;

// Start is called before the first frame update
void Start()
private void Start()
{

}

// Update is called once per frame
void Update()
private void Update()
{
if (health <= 0)
{
Destroy(gameObject);
}
if (health <= 0) Destroy(gameObject);
}

public void Damage(float damageAmount)
{
Debug.Log("hit");
health -= damageAmount;
if (health <= 0)
{
Destroy(gameObject);
}
if (health <= 0) Destroy(gameObject);
}
}
}
8 changes: 3 additions & 5 deletions Assets/Scripts/FruitFly/Navigation.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class Navigation : MonoBehaviour
{
[SerializeField] private Transform destination;
private NavMeshAgent navMeshAgent;

private void Awake()
{
navMeshAgent = GetComponent<NavMeshAgent>();
}

private void Update()
{
navMeshAgent.destination = destination.position;
}
}
}
6 changes: 1 addition & 5 deletions Assets/Scripts/Interactions/IInteractable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public interface IInteractable
{
public string interactPrompt { get; }
Expand All @@ -10,4 +6,4 @@ public bool Interact(Interactor interactor)
{
return true;
}
}
}
11 changes: 4 additions & 7 deletions Assets/Scripts/Interactions/InteractionPromptUI.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class InteractionPromptUI : MonoBehaviour
{
private Camera _mainCamera;
[SerializeField] private GameObject _uiPanel;
[SerializeField] private TextMeshProUGUI _promptText;

public bool IsDisplayed;
private Camera _mainCamera;

private void Start()
{
_mainCamera = Camera.main;
Expand All @@ -22,8 +21,6 @@ private void LateUpdate()
transform.LookAt(transform.position + rotation * Vector3.forward, rotation * Vector3.up);
}

public bool IsDisplayed = false;

public void SetUp(string promptText)
{
_promptText.text = promptText;
Expand All @@ -36,4 +33,4 @@ public void Close()
_uiPanel.SetActive(false);
IsDisplayed = false;
}
}
}
32 changes: 18 additions & 14 deletions Assets/Scripts/Interactions/Interactor.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class Interactor : MonoBehaviour
{
[SerializeField] private Transform interactionPoint;
/** Controls the radius of the interaction sphere, therefore determining how close the interactable must be to use. */

/**
* Controls the radius of the interaction sphere, therefore determining how close the interactable must be to use.
*/
[SerializeField] private float interactionPointRadius = 0.5f;

[SerializeField] private LayerMask interactionMask;
[SerializeField] private InteractionPromptUI _interactionPromptUI;
[SerializeField] private int numFound;

/** The amount of things we search for, once it's full we don't look for more. */
/**
* The amount of things we search for, once it's full we don't look for more.
*/
private readonly Collider[] _colliders = new Collider[3];
[SerializeField] private int numFound;


private IInteractable _interactable;

// Update is called once per frame
void Update()
private void Update()
{
numFound = Physics.OverlapSphereNonAlloc(interactionPoint.position, interactionPointRadius, _colliders, interactionMask);

numFound = Physics.OverlapSphereNonAlloc(interactionPoint.position, interactionPointRadius, _colliders,
interactionMask);

// TODO: Add a check that the player (and reticle) are **looking** at an interactable to prevent running when the player is not looking at it.
// This could be done by attaching to the Main Camera and reducing the size (or maybe change shape to a rectangle?) so that it isn't behind the player.
if (numFound > 0)
{
_interactable = _colliders[0].GetComponent<IInteractable>();
if (_interactable != null)
{
if (!_interactionPromptUI.IsDisplayed)
if (!_interactionPromptUI.IsDisplayed)
_interactionPromptUI.SetUp(_interactable.interactPrompt);

// TODO: Convert this check to an action from the InputSystem GameObject. (set to E and west button)
if (Keyboard.current.eKey.wasPressedThisFrame)
if (Keyboard.current.eKey.wasPressedThisFrame)
_interactable.Interact(this);
}
}
Expand All @@ -50,4 +54,4 @@ private void OnDrawGizmos()
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(interactionPoint.position, interactionPointRadius);
}
}
}
8 changes: 3 additions & 5 deletions Assets/Scripts/Interactions/TesterScripts/InteractDoor.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InteractDoor : MonoBehaviour, IInteractable
{
[SerializeField] private string interactionPrompt;

public string interactPrompt => interactionPrompt;

public bool Interact(Interactor interactor)
{
Debug.Log("Interacting with door!");
return true;
}
}
}
8 changes: 3 additions & 5 deletions Assets/Scripts/Interactions/TesterScripts/InteractWeapon.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InteractWeapon : MonoBehaviour, IInteractable
{
[SerializeField] private string interactionPrompt;

public string interactPrompt => interactionPrompt;

public bool Interact(Interactor interactor)
{
Debug.Log("Interacting with weapon!");
return true;
}
}
}
114 changes: 57 additions & 57 deletions Assets/Scripts/Player/FirstPersonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,7 @@ public class FirstPersonController : MonoBehaviour
{
private const float Threshold = 0.01f;
private const float TerminalVelocity = 53.0f;

#region User Variables

[Header("Player")] [Tooltip("Move speed of the character in m/s")]
public float MoveSpeed = 4.0f;

[Tooltip("Sprint speed of the character in m/s")]
public float SprintSpeed = 6.0f;

[Tooltip("Rotation speed of the character")]
public float RotationSpeed = 1.0f;

[Tooltip("Acceleration and deceleration")]
public float SpeedChangeRate = 10.0f;

[Space(10)] [Tooltip("The height the player can jump")]
public float JumpHeight = 1.2f;

[Tooltip("The character uses its own gravity value. The engine default is -9.81f")]
public float Gravity = -15.0f;

[Tooltip("What to multiply the character height with when crouching")]
public float CrouchHeightMultiplier;

[Space(10)]
[Tooltip("Time required to pass before being able to jump again. Set to 0f to instantly jump again")]
public float JumpTimeout = 0.1f;

[Tooltip("Time required to pass before entering the fall state. Useful for walking down stairs")]
public float FallTimeout = 0.15f;

[Header("Player Grounded")]
[Tooltip("If the character is grounded or not. Not part of the CharacterController built in grounded check")]
public bool Grounded = true;

[Tooltip("Useful for rough ground")] public float GroundedOffset = -0.14f;

[Tooltip("The radius of the grounded check. Should match the radius of the CharacterController")]
public float GroundedRadius = 0.5f;

[Tooltip("What layers the character uses as ground")]
public LayerMask GroundLayers;

[Header("Cinemachine")]
[Tooltip("The follow target set in the Cinemachine Virtual Camera that the camera will follow")]
public GameObject CinemachineCameraTarget;

[Tooltip("How far in degrees can you move the camera up")]
public float TopClamp = 90.0f;

[Tooltip("How far in degrees can you move the camera down")]
public float BottomClamp = -90.0f;

#endregion

// cinemachine
private float _cinemachineTargetPitch;
private CharacterController _controller;
Expand All @@ -79,12 +25,12 @@ public class FirstPersonController : MonoBehaviour
private GameObject _mainCamera;
private PlayerInput _playerInput;
private float _rotationVelocity;
private Vector3 _slideVelocity;

// player
private float _speed;
private float _verticalVelocity;
private Vector3 _slideVelocity;


private bool IsCurrentDeviceMouse => _playerInput.currentControlScheme == "KeyboardMouse";

private float Height
Expand Down Expand Up @@ -217,7 +163,7 @@ private void Move()

// move the player
_controller.Move(inputDirection.normalized * (_speed * Time.deltaTime * (_isCrouching ? .4f : 1)) +
new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime +
new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime +
_slideVelocity * Time.deltaTime);
}

Expand Down Expand Up @@ -282,5 +228,59 @@ private static float ClampAngle(float lfAngle, float lfMin, float lfMax)
if (lfAngle > 360f) lfAngle -= 360f;
return Mathf.Clamp(lfAngle, lfMin, lfMax);
}

#region User Variables

[Header("Player")] [Tooltip("Move speed of the character in m/s")]
public float MoveSpeed = 4.0f;

[Tooltip("Sprint speed of the character in m/s")]
public float SprintSpeed = 6.0f;

[Tooltip("Rotation speed of the character")]
public float RotationSpeed = 1.0f;

[Tooltip("Acceleration and deceleration")]
public float SpeedChangeRate = 10.0f;

[Space(10)] [Tooltip("The height the player can jump")]
public float JumpHeight = 1.2f;

[Tooltip("The character uses its own gravity value. The engine default is -9.81f")]
public float Gravity = -15.0f;

[Tooltip("What to multiply the character height with when crouching")]
public float CrouchHeightMultiplier;

[Space(10)]
[Tooltip("Time required to pass before being able to jump again. Set to 0f to instantly jump again")]
public float JumpTimeout = 0.1f;

[Tooltip("Time required to pass before entering the fall state. Useful for walking down stairs")]
public float FallTimeout = 0.15f;

[Header("Player Grounded")]
[Tooltip("If the character is grounded or not. Not part of the CharacterController built in grounded check")]
public bool Grounded = true;

[Tooltip("Useful for rough ground")] public float GroundedOffset = -0.14f;

[Tooltip("The radius of the grounded check. Should match the radius of the CharacterController")]
public float GroundedRadius = 0.5f;

[Tooltip("What layers the character uses as ground")]
public LayerMask GroundLayers;

[Header("Cinemachine")]
[Tooltip("The follow target set in the Cinemachine Virtual Camera that the camera will follow")]
public GameObject CinemachineCameraTarget;

[Tooltip("How far in degrees can you move the camera up")]
public float TopClamp = 90.0f;

[Tooltip("How far in degrees can you move the camera down")]
public float BottomClamp = -90.0f;

#endregion
}
}
Loading

0 comments on commit 3d7b362

Please sign in to comment.