News about the Unity engine and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).
How should a GameManager actually be designed?
Ok, the title might be a bit misleading… Of course I know there are many different ways to design the main logic for a game, but I’m asking this question because of the confusion “beginner tutorials” give you in this regard. I'm not a complete beginner anymore, tho my main project is still built on top of a tutorial series for general game logic in Unity.
While im pretty happy with the code readibility / quality in some newer features (leaderboards), looking at some of the untouched code the game still runs on, it looks everything but elegant. Mainly the GameManager.
1. The new endless gamemode is still part of the GameManager class, so logic for it is executed via functions which are called when the SceneName is "EndlessMode".
2. While im using the singleton pattern, I dont use DontDestroyOnLoad, and if I did it would make the GameManager even more confusing and means that I would have to use things like GameObject.Find(""), which I though was bad pratice? (Im really only using this pattern to avoid refrences)
Heres the "logic" part of the code, tho not all of the code because this question is about code design / structure and not the actual code itself:
public class GameManager : MonoBehaviour
{
private static GameManager instance;
public static GameManager Instance
{
get
{
return instance;
}
}
// Refrences via serializefields
// Some variables
public void Awake()
{
// Singleton initalization
if (currentSceneName == "EndlessMode")
{
inEndlessMode = true;
InitializeEndlessMode();
}
else
{
InitializeLevelMode();
}
}
private void InitializeLevelMode()
{
// Loading things like level prefabs / ui
}
private void InitializeEndlessMode()
{
// Loading things like prefabs / ui
}
public void Update()
{
UpdateScore();
if (inEndlessMode)
{
UpdateHighscore();
}
}
private void UpdateScore()
{
// normal code
}
private void UpdateHighscore()
{
// normal code
}
public void CompleteLevel()
{
// normal code
}
public void LoadNextLevel()
{
// normal code
}
public void GameOver()
{
if (gameHasEnded)
{
gameHasEnded = true;
if (inEndlessMode)
{
// normal code if inEndlessMode
}
else
{
// normal code if not inEndlessMode
}
}
}
public void Restart()
{
// normal code
}
}
So: How can I improved this? Im also open for any feedback
EDIT: I reformated the post, sorry for the sloppy format, I copied it from Unity Discussions out of frustation as I didnt get any answers there. Thanks for all your answers, the really help me understand what GameManager should actually be. I think my main problem was that while I always improved / updated different parts of the game (like leaderboards, a proper skin system, etc ... ) I completely forgot to update the main code (Or maybe was just too lazy...)
https://redd.it/1b83zjp
@r_Unity3D
Two ways that my games time mechanics can get players passed a locked door
https://redd.it/1b81gih
@r_Unity3D
Searching for a suitable cloud storage for my game
It's a simple quizzes game, I want to know if unity cloud is the best for storing the data or is there a better option, it will be only the questiins and scoresnof the users.
https://redd.it/1b7xexl
@r_Unity3D
Is there an easy way
Hi, im doing a cooking game on unity and i wanted to do a minigame similar to those filters that are everywhere on tiktok where you have to cut a picture and it separates the rest gaining point dependimg on how close you were.
Could do the points and result with a slider or something similar but i dont know if the cut the sprite in half could be done. Any idea?
https://redd.it/1b80264
@r_Unity3D
left is blendr, right is unity. why does it look different in unity
https://redd.it/1b7vyf9
@r_Unity3D
Same game, 6 months ago vs today
https://redd.it/1b7mvdl
@r_Unity3D
Hello, I have a question. It seems that the floors in Diablo 2(original) are made of individual isometric grid tile images, but the grass and dirt blend together naturally. How can I implement this style in Unity?
https://redd.it/1b7u1cl
@r_Unity3D
Is the Legend of Nasir Gebelli Really a Legend?
On Wikipedia'sJapanese page for Nasir Gebelli, there's a fascinating anecdote mentioned:
>During the development of "Final Fantasy III," a significant bug emerged, prompting the team to consult Nasir. Remarkably, he dictated the exact portions of the code that needed fixing over the phone, astonishing the developers receiving the call, including Hiromichi Tanaka. Hironobu Sakaguchi shares a similar story, where, after Nasir had returned to his home country due to visa issues, a bug was discussed over an international call. Following Nasir's instructions to the letter over the phone led to the bug being fixed.
When I first read this story online, I was astounded.
However, as someone who continues to work on personal development projects in UNITY, I can imagine being called while away from my desk about a bug in a class I've been wrestling with for a while. While I might not remember every line, I believe I could provide detailed verbal instructions on how to resolve the bug.
Am I legendary programmer?
https://redd.it/1b7say0
@r_Unity3D
Free Pixel Frames, Buttons, Panels Part 1B
https://redd.it/1b7lpop
@r_Unity3D
Trying to add a delay for my Tetris blocks but they just zoom down
I'm trying to add a delay between each block movement (Moving down 0.5f relative to world space) but after the initial delay it just zooms down and then stops at -1 (Trying to stop it at -0.5). Can someone help me figure out why this isn't adding a delay between each movement?
Code:using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallingBlocksScript : MonoBehaviour
{
//Move down in incriments of 0.5, 26 times
private float DownMovesLeft = 26;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (DownMovesLeft <= 26 && DownMovesLeft != 0)
{
StartCoroutine(FallDelay(1.0f));
DownMovesLeft -= 1;
}
}
IEnumerator FallDelay(float v)
{
if (DownMovesLeft <= 26 && DownMovesLeft != 0)
{
yield return new WaitForSeconds(3);
transform.Translate(0, -0.5f, 0, Space.World);
}
}
}
https://redd.it/1b7nhmk
@r_Unity3D
How can I get my player to be in the foreground (with collisions)?
https://redd.it/1b6xahf
@r_Unity3D
How to use UnityExplorer?
IM not too sure if this is relevant to this subreddit. I am curious.
https://redd.it/1b6v9c8
@r_Unity3D
Pixel Frames, Buttons, Panels Part 1A
https://redd.it/1b6rnro
@r_Unity3D
How are the ragdolls looking? I've tried to make enemies react differently depending on where you hit them
https://redd.it/1b6cn5t
@r_Unity3D
Crating a game for college
I'm making a beat 'em up game in Unity 2D and can't find any books or videos to help me build a decent enemy A.I. Can you guys give recommendations of books (that are not dated) or videos that will help me build a decent enemy for this kind of genre?
https://redd.it/1b6ldfb
@r_Unity3D
C++ in the editor, natively! Much faster compile times than C#. Supports any IL2CPP target.
https://redd.it/1b803vt
@r_Unity3D
'The Leader' sharpens his blade in preparation of the battles to come.
https://redd.it/1b83ctb
@r_Unity3D
Hey everyone, released a new (and, hopefully, final) version of the demo of the first game I'm currently developing. I will start the development of the final game so I'm looking for feedback.
https://www.youtube.com/watch?v=bOGCF4Hu2vk
https://redd.it/1b813wu
@r_Unity3D
Question about PlayerPrefs
Hi people! me again. Just wanna know a thing about playerprefs. If i use playerpref in the level menu scene so that it can remember how many stars are collected in a certain level and display it in the level menu scene, will it still be there if the player exited the app and removed it to the phone's recently opened tabs/applications and tried to play it again?
(if not, then I guess I really need to do the JSON thingy)
https://redd.it/1b7z02w
@r_Unity3D
Pixel art Themed Horror game
https://redd.it/1b7wnm4
@r_Unity3D
My partner and I lost our jobs in the games industry, so we've been making this VR tower defense with our savings. Does it still count as fantasy if there are gatling guns and guided missiles?
https://redd.it/1b7tmyw
@r_Unity3D
Return bool does not work.
https://redd.it/1b7t5rf
@r_Unity3D
Good resource for structuring a scalable design for Enemies/Units (Specifically related to animator)
I'm interested in what an effective design pattern would be a game that would have many enemies, say hundreds just for conversations sake.
I've tried digging into open source repos and haven't seen an effective solution.
I'm, aware of the scriptable object / FSM patterns etc, I'm more looking at the animator component. In larger games using Unity, are they actually using the Animator state machine for each enemy/unit introduced into the game? That seems tedious and messy.
Ideally, there would be a quick way to create new variations of enemies on the ui, plugging in SOs and animations and acs, with some type of script that controls the animation names and states that is common to all or most units.
Any thoughts on this?
https://redd.it/1b7oz6w
@r_Unity3D
Having trouble making a background image remain static when I zoom my orthographic camera.
I have a solar system map that is made up of real game objects (not UI). I want a stationary starfield in the background that doesn't move/zoom away when I change my cameras orthographic size.
Anybody point me in the right direction here? Basically I'm looking for a 2D skybox.
thanks!
https://redd.it/1b7mxur
@r_Unity3D
Floramancer: Seeds and Spells - Out right now!
https://youtu.be/7iPhWR2GBYs?si=YQ_rRpTBcIDxdU0Q
https://redd.it/1b7lwve
@r_Unity3D
Help! NavMesh components look completely different in Inspector.
I am trying to set up pathfinding for my 2D PacMan game and I have been trying to follow tutorials on how to implement NavMesh. (One of which is: https://www.youtube.com/watch?v=W-NIYi1t16Q). But when I follow the steps, my inspector looks completely different.
So far I have encountered these issues:- in the NavMesh Modifier, no "Area Type" dropdown appears when I select Override Area.- in the NavMesh Surface there is no cylinderal blue diagram, no bake option, nothing. It looks completely different.- also no rotate to XY button.
I do not know what I am doing wrong. I am using Unity 2022.3.18f1.
I did also try making a brand new project, but it had all the same issues.
​
Full view
On GameObject
On GameObject
On Tilemap
https://redd.it/1b6wtvd
@r_Unity3D
Spent 8 hours on this...
https://redd.it/1b6t77c
@r_Unity3D
Melhores Bibliotecas unity 2D
Quais bibliotecas vocês indicam para baixar no vscode se você está progamando um jogo 2D na unity?
https://redd.it/1b6rxek
@r_Unity3D
⭐ How do you like the look of my gardening game? 🌿😊 WIP - open for feedback!
https://redd.it/1b6l5te
@r_Unity3D
Why is my dash reach inconsistent!?
Hello, I'm starting my first unity project, and wanted to know what I'm missing here. What's supposed to happen is: player clicks, character does a dash towards the mouse. I've put the pink line there just to measure the distance, and if you pay attention, sometimes the rectangle goes a bit above the line limit and sometimes it doesn't. Why does this happen?
The specific line that moves the character:
>while (Time.time < endTime){
rb.velocity = dashDirection * (dashDistance / dashDuration);
yield return null;
}
Is it a velocity thing from the rigidbody? Should I be using other methods to do this? I've put a log there and it always returns the same velocity, this is driving me crazy!
😔
https://redd.it/1b6kef5
@r_Unity3D