Posted May 23, 2024 by Jonarella - KAOS
This week, I finished the new movement system for now. My focus shifted to the text system, which is almost done, and reworking the quantum mechanic to fit the new input and movement systems. This script is halfway done and has been challenging. I’m learning how to use IEnumerator (Coroutines) in Unity, which is tricky but necessary for this mechanic. I also started planning collectible items. In my game, you need to gather 4 objects to unlock the final area. I’m thinking of using a “GameManager” object to count these items and unlock the area when all are collected.
Scripts
ObjectPickup
RespawnManager
TextPromptSystem
In Action
The new movement system is flexible and supports various controllers. The text prompt system works well, but the quantum mechanic script is challenging due to coroutines. Planning for collectible items is underway.
Coroutines in Unity: Coroutines allow you to run code in parallel to other code, which is helpful for tasks that need to wait or run over multiple frames, like animations or timed events. Using IEnumerator
and yield return
statements, coroutines can make code cleaner and more efficient for specific tasks. For example, my coroutines are used to move the character smoothly to the wall when detected:
IEnumerator MoveToPosition(Vector3 target, float speed)
{
isMoving = true;
playerCollider.enabled = false;
movementController.enabled = false;
while (Vector3.Distance(transform.position, target) > 0.1f)
{
transform.position = Vector3.MoveTowards(transform.position, target, speed * Time.deltaTime);
yield return null;
}
transform.position = target;
isMoving = false;
}
GameManager: A GameManager is an empty object in Unity that manages game-wide systems and logic. For my game, the GameManager will track collectible items. When the player collects an item, it sends a signal to the GameManager, which counts the collected items. Once all items are collected, the GameManager will unlock the final area of the game. I will need to create two scripts: one for the pickable object to send the info that it was picked, and one for the GameManager to receive it and keep track of how many were picked.
End of DevLog Week 4.