diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index ddb6ff8..1eb21de 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -1,5 +1,6 @@
{
"recommendations": [
- "visualstudiotoolsforunity.vstuc"
+ "visualstudiotoolsforunity.vstuc",
+ "aaron-bond.better-comments"
]
}
diff --git a/Assets/Scripts/PickUpObject.cs b/Assets/Scripts/PickUpObject.cs
index 0860203..259a8f8 100644
--- a/Assets/Scripts/PickUpObject.cs
+++ b/Assets/Scripts/PickUpObject.cs
@@ -10,101 +10,89 @@ public class PickUpObject : MonoBehaviour
{
public GameObject carryPosition; // blank object, position declares where the object will be teleported to/carried
public bool insideTrigger = false; // checks if player is inside the trigger of a pickup object
- public bool carrying = false; // checks if player is carrying an object
- public GameObject carriableObject; // object newest object that player can carry
+ public bool playerIsCarrying = false; // checks if player is carrying an object
+ public GameObject nearestCarriableObject;
public GameObject previousObject; // previous object that player was carrying
public GameObject heldObject; // object that player is currently holding
- public float throwForce; // force that player throws object with
- public float cooldown; // time between picking up objects
- public bool cooldownActive; // checks if cooldown is active
+ public float throwForce;
+ ///
+ /// Cooldown time between picking up objects in seconds
+ ///
+ public float cooldownSeconds = 1;
+ public bool cooldownActive = true;
+ public KeyCode interactKey = KeyCode.F;
// Start is called before the first frame update
void Start()
{
- cooldown = 1;
- cooldownActive = true;
+
}
// Update is called once per frame
void Update()
{
- // Checks if timer is below 0, if so, turns cooldownActive off, if not, activates cooldown
- cooldown -= Time.deltaTime;
- if(cooldown <= 0)
+ // * Cubes are quite hot so need time to cool off
+ cooldownSeconds -= Time.deltaTime;
+ cooldownActive = cooldownSeconds > 0
+
+ // * Old objects deserve gravity too
+ if(previousObject != null && previousObject.GetComponent().useGravity == false)
{
- cooldownActive = false;
- }
- else
- {
- cooldownActive = true;
+ previousObject.GetComponent().useGravity = true;
}
- // If previous object is not held object or null, applies gravity to it
- if(previousObject != null)
- {
- if(previousObject.GetComponent().useGravity == false)
- {
- previousObject.GetComponent().useGravity = true;
- }
- }
-
- // If player is inside trigger and presses F, pick up object
if(insideTrigger && Input.GetKeyDown(KeyCode.F) && !cooldownActive)
{
- // Disables gravity on object and sets carrying to true
- carriableObject.GetComponent().useGravity = false;
- carrying = true;
- // Sets held object to carriable object and sets cooldown to 1
- heldObject = carriableObject;
- cooldown = 1;
+ // * Who needs gravity
+ nearestCarriableObject.GetComponent().useGravity = false;
+ playerIsCarrying = true;
+ heldObject = nearestCarriableObject;
+ cooldownSeconds = 1;
}
- // If player is carrying object and presses F, drop object
- else if(carrying && Input.GetKeyDown(KeyCode.F))
+ // * YEET
+ else if(playerIsCarrying && Input.GetKeyDown(KeyCode.F))
{
- // Re-enables gravity on object and sets carrying to false and assigns held object to previous object
heldObject.GetComponent().useGravity = true;
previousObject = heldObject;
- carrying = false;
- // Drop the object in the direction the player is moving and add a force to it depending on speed
+ playerIsCarrying = false;
previousObject.GetComponent().AddForce(transform.forward * throwForce, ForceMode.Impulse);
+ Debug.Log("Yoted!")
}
- // If player is carrying object, teleport object to carry position
- if(carrying)
+ // * Cubes not stored above heads are highly dangerous
+ if(playerIsCarrying)
{
- carriableObject.transform.position = carryPosition.transform.position;
- carriableObject.transform.rotation = carryPosition.transform.rotation;
+ nearestCarriableObject.transform.position = carryPosition.transform.position;
+ nearestCarriableObject.transform.rotation = carryPosition.transform.rotation;
}
}
- // If player is inside trigger tagged as PickupObject, set carriable object to object inside trigger
- void OnTriggerStay(Collider other)
+ // Called when the player is inside a trigger tagged as PickupObject
+ void OnTriggerStay(Collider otherObject)
{
- if(other.gameObject.tag == "PickupObject" && !cooldownActive)
+ if(otherObject.gameObject.tag == "PickupObject" && !cooldownActive)
{
- carriableObject = other.gameObject;
- // If player is inside trigger, set inside trigger to true
+ nearestCarriableObject = otherObject.gameObject;
insideTrigger = true;
- // If player is holding an object and it is not the carriable object, set previous object to held object and set cooldown to 1
- if(heldObject != carriableObject && heldObject != null && carrying)
+ // * old cube is boring
+ if(heldObject != null && heldObject != nearestCarriableObject && playerIsCarrying)
{
previousObject = heldObject;
- cooldown = 1;
+ cooldownSeconds = 1;
}
}
}
- // If player is not inside trigger, set inside trigger to false
- void OnTriggerExit(Collider other)
+ // If player is not inside trigger, then they probably aren't inside it
+ void OnTriggerExit(Collider otherObject)
{
- if(other.gameObject.tag == "PickupObject")
+ if(otherObject.gameObject.tag == "PickupObject")
{
insideTrigger = false;
}
}
}
-
//! To make player launch self:
//! add public GameObject player; and place player in it fron inspector
//! in if(insiderTrigger && Input.GetKeyDown(KeyCode.F))