#💻┃code-beginner
1 messages · Page 289 of 1
Hey all! I cant seem get a straight answer out of anyone. Whenever I move, my camera jitters, its not smooth, and I cant bring myself to move on without fixing it. Can someone please help?
(I am new to unity by the way)
PlayerMove Script : https://gdl.space/kizodiqeri.cpp
CameraMove Script : https://gdl.space/calahopeba.cpp
CameraControls Script : https://gdl.space/ahevasitej.cpp
yeah that must have been it
yet all I have is different Cinemachine names
like what cinemachine am i supposed to use?
i only see 1 here
are we not looking at the same image
and its already installed it seems, so just learn how it works and components avail
i meant this
ohh
probably Virtual Camera, this should add a Cinemachine brain on the already there Camera
i am unsure what you mean by different cinemachine names. can you clarify?
@hushed hinge have you looked up a guide?
There are many out there
I did, I was trying to find that camera one thing, but I cannot find the one which matches
okay, this makes sense. now you have to look for a cinemachine tutorial on what you want to achieve . . .
Cinemachine Virutal Camera is general purpose
like this
try this one out, a tutorial, that is . . .
#💻┃code-beginner message
oh just 1 ? or both players
This really isn't a code question btw
There is a #🎥┃cinemachine channel
are you talking about removing the black line viewport ?
that's not what i meant
It has pinned resources too
What? Respond to wrong person?
no
Then that response makes absolutely no sense
it's just for player 1 (single player)
oh ok, so you dont need the target group on i linked earlier.
Just use regular Virtual Camera
but yeah this isn't coding related
also, I don't know if it have to do with cinemachine because there's usually coding
you dont need any scripts for cinemachine follow target
cinemachine is a pretty advanced system.. u can do almost everythign from the inspector
since i have a camera script for the 2 players
cinemachine can follow 2 objects ez
Coding can be discussed in #🎥┃cinemachine if it's about cinemachine of course....
ofc you don't want body to be 3rd person follow, but you can see Follow can just be linked directly
I sent that too thinking they needed both players but apparently only 1 😛
ez
it just won't work, also what type of camera i meant is that the camera doesn't just so instant focus on the player like the player can move around in the camera a bit around
How can I see/fix whatever is cutting off weapons from the player's camera view?
I turned off mesh renderer for the player capsule it doesnt stop the cutoff
is it just how the camera works that it starts considering objects at a certain plane?
near clipping plane of the camera
In the body of the virtual camera use Transposer
Play around with damping. Also all further cinema questions goes in #🎥┃cinemachine
When I try to publish a game, it loads to 90%
But I have used https://forum.unity.com/threads/fix-for-unity-2020-webgl-build-stuck-at-90.949254/ this to help me. It worked for a bit until now and its still on disabled
what on earth is this
it just added that stuff
and changed UnityEngine.AI to using UnityEngine.UI
auto complete will also add the libraries needed if you mistakenly allow it
how do i check if the path is completed with navmesh?
as in, check if the agent reached the destination
Vector3.Distance , invoke event
is there no built in navmesh function for it?
like hasPath etc
Oh guess yea remaining distance to check. 👆
Not sure has path would work well
There is no built in event sadly which is kinda weird but oh well
👌
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseMovement : MonoBehaviour
{
public float mouseSensitivity = 100f;
float xRotation = 0f;
float yRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
yRotation -= mouseX;
//clamp the rotation
xRotation = Mathf.Clamp(xRotation, 90f, 90f);
}
}
Don't multiply mouse input by deltaTime
It's already a delta
Why is this necessary here ?
xRotation -= mouseY;
yRotation -= mouseX;
I think it should be
yRotation -= mouseY;
xRotation -= mouseX;
XRotation is the rotation around the x axis (think of a horizontal bar) which moves the camera up and down
oh, why is that? ( just genuinely asking, not being stubborn or anything )
Because rotation about the Y axis is looking left/right. Imagine a pole through the Y axis of the object, then spinning the pole
Because mouse input is already a delta
Meaning a change since the last frame
GetAxis is already framerate independent. Multiply deltaTime actually makes your mouse go slower at higher framerates
Then why not also have a zRotation -= something;
?
any idea what I've done wrong, I can't figure it out at all https://gdl.space/atigosowax.cpp
Because that would be rolling side to side. Remember, Z axis is forward
There's very little reason for a 3D object to rotate about the Z axis
do you guys recommend [SerializeReference] along with [SubclassSelector] from mackysoft or just use scriptable objects
theres not much of a difference correct? besides the fact that two thingns cannot hold the same reference
Holy crap I had no idea this thing existed:
https://github.com/mackysoft/Unity-SerializeReferenceExtensions
haha
Man
There's probably a few of them out there
this can effectively replace scriptable objects right?
besides the fact that I noted
It's more fragile, but it can be a replacement at times
yeah thats what I was worried about, everything losingn references
is that an issue?
personally I try to avoid it unless it's solving a larger usability problem
noted
because Im making a ton of abilities made out of up to 10 scriptable objects and was thinking it would be much easier to do this with subclass selector
but if something happens and I have to reassign all my abilities that would suck
stick with SOs i assume?
I can't really give much recommendations, I would just exercise caution in regards to liberally applying the attribute. If you're in a state of doing regular refactorings it can complicate things. If you apply SerializeReference to arrays it can also easily break things because adding to the array creates an annoying duplicate that references the same item as the last instead of a copy.
I haven't touched it for a while because I'm doing ECS stuff and it's mostly unnecessary for me
so in general, if I want to avoid weird stuff happening just stick to SOs
Certainly is the most robust way of going about things, though can be annoying having to create extra objects
👍
macky has some other neat utility too
the weighted selector is fun
but beyond serialized references and SOs, mostly a mix between SOs with plain c#
serialize references are nice for interfaces, but I've kinda abandoned that idea
https://i.imgur.com/YibpI3h.png
SO into SO into SO
less SO's than me lol
looks really good
one ability that isnt even finished lol
cant think of a better way to do it tho
haha seems like just how it is cause ive a directory per ability too
yep lol
what is meant by "trigger", i remember you guys talking about them and how it was difficult to implement
it's just adding conditions to your ability for when you want to do some recursive ability actions
I think they call the pattern meta magic or something
instead of making the whole ability as one, just chop it into components -> fireball -> fireball explodes
i kinda just hard code that
since i have different stages of the ability, it works out
pre activate, activate, post activation etc
yeah, that's probably fine. I was thinking maybe ill reuse stuff
yeah it is more modular
sword casts level 5 fireball explosion
you could allow the player to make custom abilites
that do wacky things
thing is, I was wondering how to allow that. for example, if a player has say "poison chance", i want the basic bow attack to then have the poison effect which seems like it would require assigning things to the SO from somewhere else
I got a problem here guys, i tested a bit that in unity i can collect the rubies, but in game i cannot collect them
or should I just already have all those effects on it and only if the stat is above a certain amount say posion chance > 0, then it would apply
what do you mean you can collect in unity
if it's just a numbers thing then I'd feel like it would be another iterate over a list of applications when you hit the target kind of thing
I meant in making the game editing unity
me?
no, but make sure your colliders are set correctly
if you're using ontrigger methods then you need at least 1 rigidbody and 1 trigger collider (both must have colliders though)
well that is just an example, say I have some modifier that makes all attacks do an explosion effect, I would have to somehow assign that effect to all abilities
when the player gets access to that modifier
atleast in the way im doing things right now
some passive system right
yeah
and im trying to avoid hard coding every ability to have knowledge of all the possible "states" it could have
I'd tackle that by scrolling over a list of passives that apply at the target direction when the target is hit
it works in unity making
so invert it?
make it so the caster or target has the list and all abilites would just read from that list whatever it may be
like imagine gloom shrine in POE
When target is hit -> Ability.Cast(IEnity Target)
two things to think about is the direction the ability comes from (Does it come from the target or does it appear at the target)
I jsut don't get why it doesn't work in the actual game
What is the method you are using to collect the stars
i might be thinking of something else, would that not require the entity to store all of those possible things already?
rubies, not stars
for example, i have a list of status effects on my bow attack, which are just an Effect similar to the Damage Effect, Cooldown Effect etc, if I could just add Poison Effect when the player has poison, that would solve the issue
these Effects are all scriptable objects also
yeah that's just numbers stuff, but assume you do want another projectile to spawn from you like say if you hit an enemy you have a 20% chance to cast a fireball from you
that itself is basically another ability you have, but you don't manually cast it but you treat it as any other ability with some automated targeted conditions you give it
it worked before when i changed the text to meshtext ui
does your character have a rigidbody and a collider?
I think the problem might be with your Find method
so my question is, how do I assign that to my Bow Attack SO when say the passive is allocated, and remove it when it is not
yes
I don't have multiple options
click the arrow
when i said that, i meant it doens't have multiple options, no arrow
my idea is not to make it part of the bow per say, but as another individual component to the bow. In PoE, poison is more like a global effect that applies to all attacks usually
in general?
just build it again
it always worked before
well, as you work on stuff, sometimes stuff you previously worked on breaks so it's worth to debug.log to make sure where the error may be
there's no error
yes, but with my system, that Effect would have to be applied by the ability
I need to get this fixed, I don't get why it doesn't work in game
ah maybe just make all of those thingns innate to any projectile
what?
not you, im sorry
PoE has both local and global stuff, but usually it comes down to what and how much you want to iterate when you hit some character
like, make as many conditional containers you want, when you hit an enemy if you have a passive container with behaviour that targets the enemy, then just check if it's empty or not
I have no children in there though
my effect system / ability system has both. When I equip an ability I look through all modifiers and add it to the ability like a normal component if the tags are compatible
maybe that's what you're thinking of
perhaps I could include it as part of my AbilityInstance
so how do i fix this, please?
since i have my ability definiton SO
when I equip an ability, I look at all previous modifiers (including stuff like effects) and then do some bitwise operations, then I populate the ability's containers with all the modifiers you can use
ability hits -> iterate over the containers
do you populate the SO or some instance of the ability?
when I new the ability I have some subscribe to a observer system on the actual instance (it can already have some effect original to it, and I would keep track of what is a modifier and what is original to it)
I DON'T GET WHAT I'M SUPPOSED TO DO
Hi, I'm looking for a forum to find a paid Unity tutor, does anyone have any recs?
I AM SO CONFUSED; I don't have any chidlren in there
so I think I do something similar, I have my ability definition with all of its effects, and then an ability instance which holds a reference to that Ability SO but also has references to the caster and functions to activate etc
Start adding debug.logs into your OnTrigger method and make sure what conditions are working
stop pinging me bro, try to make a development build
then u can use debug logs there
targeting abilities is a pain though
probably the biggest problem with making these controllers
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Counter : MonoBehaviour
{
private TextMeshProUGUI _text;
private int _amountPickedUp = 0;
private int _allPickups = 0;
public int levelNumber = 1;
private void Start()
{
_text = GetComponent<TextMeshProUGUI>();
FindAllPickups();
_text.text = _amountPickedUp.ToString(); //+ "/" + _allPickups.ToString();
}
private void FindAllPickups()
{
GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("Pickup");
_allPickups = gameObjects.Length;
}
public void PickedUp(int value)
{
_amountPickedUp += value;
if(_amountPickedUp >= 100)
{
RemovePickups();
GameObject.FindGameObjectWithTag("Player Manager").GetComponent<PlayerManager>().AddLife();
}
_text.text = _amountPickedUp.ToString();// + "/" + _allPickups.ToString();
if (_amountPickedUp >= _allPickups)
{
PlayerPrefs.SetString("Gems" + levelNumber.ToString(), "Clear");
}
//for (int i = 1; i < 8; i++)
{
//print("Gems" + i.ToString() + ": " + PlayerPrefs.GetString("Gems" + i.ToString()));
}
}
private void RemovePickups()
{
_amountPickedUp -= 100;
}
}
what development build?
like giving it a target to move toward?
that is unreadable !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
when you make a build, there is an option to make it a development build where you can use debug.log statments
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Counter : MonoBehaviour
{
private TextMeshProUGUI _text;
private int _amountPickedUp = 0;
private int _allPickups = 0;
public int levelNumber = 1;
private void Start()
{
_text = GetComponent<TextMeshProUGUI>();
FindAllPickups();
_text.text = _amountPickedUp.ToString(); //+ "/" + _allPickups.ToString();
}
private void FindAllPickups()
{
GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("Pickup");
_allPickups = gameObjects.Length;
}
public void PickedUp(int value)
{
_amountPickedUp += value;
if(_amountPickedUp >= 100)
{
RemovePickups();
GameObject.FindGameObjectWithTag("Player Manager").GetComponent<PlayerManager>().AddLife();
}
_text.text = _amountPickedUp.ToString();// + "/" + _allPickups.ToString();
if (_amountPickedUp >= _allPickups)
{
PlayerPrefs.SetString("Gems" + levelNumber.ToString(), "Clear");
}
//for (int i = 1; i < 8; i++)
{
//print("Gems" + i.ToString() + ": " + PlayerPrefs.GetString("Gems" + i.ToString()));
}
}
private void RemovePickups()
{
_amountPickedUp -= 100;
}
}
more that when you have these automated targeting conditions through triggers it changes the behaviour of your abilities usually. In PoE you have abilities that you personally would target, but when they are trigger then you sometimes need some automated logic
ah I see, like find closest enemy etc
everything worked before in game before it no longer works when i changed text to textmeshpro
What error are you getting?
turn off the collider on the textmeshpro
there's no error
maybe thats the issue
yeah stuff like that but sometimes I overscope and want to do fun stuff like hey wouldnt it be cool if instead coming from the player it would spawn on top of them and stuff like that
So what does "doesn't work" mean?
I see no collider on the textmeshpro though
I meant like it doesn't work IN-GAME that i'm unable to collect the gems and the coutner doesn't go up even though it works in the game making editing
sorry, was thinking of raycast target, nvm that
oh
How are you assigning it?
make a development build and try debug log statements
how do i make a development build?
ah, and have it modular as well, i see how that could be hard
what?
Your tmpro var is private, how are you assigning it?
You're not doing it in the inspector
_text = GetComponent<TextMeshProUGUI>();
How are you "referencing" it
Whoops I didn't see that bc of how awful it's formatted
Change tmprogui to TMPro_Text
if you want to start out with something very flexible, instead of just casting from the point of the player, give the ability two points in space. The start location and target location. Two points makes a direction, but this allows you to say offset the position by 10 units y, but 5 unity y on the target. This would make the ability spawn above with a direction downwards towards the player. Then say you add 5 z local to the target, now you have it spawn 10 units above with a 45 degree angle downwards basically
im in 2d, but I see how that could be interesting
oh, still probably relevant if you want stuff from spawning in front of you and then going into your direction towards the player and fun stuff like that
tmprogui?
Private TextMeshProGUI _text;
yeah then i could just use any point in space such as the enemy location to fire it from despite it being cast from the player
and do the cool things like you said
TMPro_Text _text
doesn't work
hello, all my scripts say Assembly Infromation Filename Assembly-CSharp.dll
I imported a new asset that has scripts with a different Filename and references a Definition File Destructible2D.
I'm trying to edit some of their scripts to reference my own scripts and it doesn't work. How should I change the imported scripts Assembly Definition to be able to reference my other scripts?
doesn't work either
Ah I believe it's TMP_Text
Wait maybe that's for classes
Nvm it's for both
Quaternium 😭
Oh
i'm a girl
her
snf i just used the debug
did you make a dev build like i said
I said I don't know how
yes its the base class
and both can use it
UI version and mesh version
THATS WHAT I SAID AND UMBRA IS GASLIGHTING ME
doesnt TextMeshProGUI work just the same though
TPM_Text is preferable because its shorter to type as well
why would that make the collider not work in build
lol
don't think there is anything specific to the child class TextMeshProUGUI
worth checking though ig
What collider? I thought it just wasn't updating
Oh
@hushed hinge you've had me on this mouse chase for nothing 🤦♂️
Listen to your superiors
and therefore because they arent being picked up, the countner isnt updating
its not an issue with the counter itself
It's literally just a check box right above the build button...
Do I need to learn C# before starting the unity learning?
it could be related to the counter if it is erroring in the build
Yes most definitely
You can learn it concurrently in !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i started with 0 knowledge but u probably should lol
but I'd like to see some debugging to actually figure out what's not being triggered
but Unity uses c#, so you will obviously need to know it
Any recommendations for a program?
What does that mean?
To learn C#
a program for what
W3Schools
TutorialsPoint
Microsofts own guide
don't pay for anything
Skip youtube until later
So unity Essentials then Junior Programmer?
c# then unity
what?
Yeah, if you wanna skip doing pure c# first, do that
or do one of the sites I mentioned above to learn JUST C# first
You're issue has nothing to do with TMPro
"What" is a really useless response. See #854851968446365696 about that
I think learning C# first would be more beneficial
it certainly will make it easier to understand whats going on in unity
what's the issue?
Listen to umbra, he isn't sending cosmetic messages
issue is not debugging and senseless chattering on an issue you could probably solve quickly
[System.Serializable]
public class Biome
{
public NoiseSettings noiseSettings;
[Range(0.0f, 1.0f)]
public float minTemperature;
[Range(0.0f, 1.0f)]
public float maxTemperature;
[Range(0.0f, 1.0f)]
public float minPrecipitation;
[Range(0.0f, 1.0f)]
public float maxPrecipitation;
}```
How do I make it draw the min and max like a single value. Like, a range with two sliders. I remember seeing an editor window with that before but I forgot where.
even though I googled how to make dev build, i cannot find the tutorial of that
As I said, it is just a checkbox right above the build button....
start with the Programmer path
there is also this one which was what I learned when I joined
https://learn.unity.com/project/beginner-gameplay-scripting
yes
but this is for vectors
Awesome thank you
@hushed hinge
I honestly wouldn't trust any directions you tell me to follow bc of light mode 🤮
Requires the naughty attributes package as it's not part of unity's attributes
I know.
and the build and run?
You really... can't guess that?
I am not a pro on shorten names
shorten names?
when you shorten the name development build to dev build
also, I just asked "and then build and run?"
I saw you asked that. I am confused why. And why you are talking about short names?
She was confused bc she didn't realize dev build and development build were the same thing
Why have you asked this many times instead of looking it up or trying?
I don't know what to pick
Instead of looking it up
looking up the difference would tell you which one to pick
one builds the game and runs it, one just builds it
as the names suggest
do you want to run it?
I meant the last 4 choices below Development build
those aren't connected
Ah, you never said that. Be more clear.
You should look each of those four up.
But no, you shouldn't need them
Oh
build and run is especially handy for tesiting WebGL as it creates the server for you when you build in run, otherwise you'd need a server to run JS in local browser for security issue from browser
So unity removed their 2d vector composite from Input Actions, what can I use instead?
its not removed?
It is not removed
seems like i get errors when i touch the rubies
Show your console in the actual editor
what do you mean?
in the actual editor?
The composite is still there, but the action you created was set up wrong, so it is not available
Yes
which action type have you selected?
i did not get what you mean
In Unity. The Editor. Not the build
Button is wrong
its on button by default
Composite is not a button
how can i show it? there's no error in unity
Show the console
I didn't say show an error
what console?
whats a composite?
Are you serious right now? It's the thing that WOULD show errors. Or logs. Or warnings
how did you get so far into a game without knowing what a console is?
gpt code lol
it was just this year
On my phone, so can't look at it. Just select the different types till you find composit. Or google it
Sorry
i have these two scripts but on my editor it gives me a warning Assets\Scripts\Stats\SlimeStats.cs(24,18): warning CS0108: 'SlimeStats.sightRadius' hides inherited member 'EnemyStats.sightRadius'. Use the new keyword if hiding was intended.
and also i cant find the "Slime" option to add to my assets
well be mindful it will not teach you anything, its best you learn the essentials of unity directly first so you can recognize when its wong etc.
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
You made the same variable name in the parent and child class
i mean its abstract i thought id have to define what the variables are
Why are you showing me this?
You do, but not as new variables
Wait, this whole thing is weird
oh so i just have to remove the stuff before the variable name
I thought i should show this?
Why?
I asked for the console
your ide isnt configured, follow the bot message that was linked above.
also this seems like a weird use for scriptable objects. just create an instance of EnemyStats
All of these have a composite type except for the first option. So my question is which one of these is more closely matching the former 2d vector composite option?
I think the last one?
and that is what i meant by there's no errors
there is errors though what are you looking at
I do not care about that. It is not relevant. Show the the console
Why are you fighting this?
I mean this layout
u should really take a step back and go learn the absolute basics of coding (outside unity) or just whatever beginner unity learn tutorials there are. surely some unity learn page will talk about the console
None
I'm not fighting
its still there you just now have to select the correct Action Type
Why are you responding instead of SHOWING THE CONSOLE
Saying "there are no errors" instead of just showing the console is fighting imo
what would creating a new instance look like
my screenshoot is loading slow, calm down
it's cropped. And there are errors
first configure your IDE, then worry about this.
#💻┃code-beginner message
its downloading rn
after you do the IDE thing, it is just created in the assets folder. Thats what the CreateAssetMenu attribute is used for, you can create an instance of it that lives in your project.
oh got it
what are u downloading exactly
cause you already got VS
probably the unity module on vs
downloading update
ah workload
i already have unity module installed
then you probably just need to regen project files
how would i do that
It's in External Tools of Unity, where you choose the ide unity uses
alright
cool 👍
The GC Handle?
try disabling lights inside the scene view, see if that goes away
No.
You didn't run the game after the build, so the console wasn't updated
But, as suggested, I'm gonna "calm down". Best of luck. Seeya
What, what i do wrong with the run and build?
your build does show errors so I suggest going to the line they are at and throwing some logging down
the logging should show in the build log
How do I do that?
by learning how to debug your code by printing to console
Im trying to save my progress that I made so far to ensure that this project will be there tomorrow. So my question is why is it that when i hit save or ctrl+s file exporer opens up in this asset folder directory instead of just automatically saving my project that it already exists as a collection of files? Also when I look for the project's name on my file exporter, it says open and then you have to save this file as a game's ASSET. Does it make any sense that you would save this entire project file inside of it's own assets as a game asset ?
the button says open up when i go dir over this entire unity folder
so you have to open it, and then it says save
so i can literally save it as an asset or something
you can't just ask how to do everything, learning is figuring things out on your own
debugging is one of the most essential things to programming
look up how to debug in unity
I've never done that before
really, take a step back and go learn the basics. you arent gonna get far just by trial and error. Most people here wont spoonfeed you everything
I saw debug logs in your video from before, is your whole game made from copy pasting code?
oh okay, so this entire thing has to be saved as a scene inside of its own scenes interesting
got it, anyways, thanks
No
gotta be gpt or just blindly copying tutorials/other code.
both
No, I got a lot of help from my teachers
Ctrl+s saves the scene. So yeah, I guess that was the first time you saved that particular scene?
Debug.Log is used similarly to print in your generic language of choice
then either your teachers are shit, or you skipped out on some lessons early on. Either way, the solution is to google so you can learn
I remember seeing the notes she got from teachers like months ago, and yeah.... not great at all
How do I ever do that in the build even though they are not shown in the console?
That's now what I meant, I am in the dev build, and i already did that
Don't say that about my teachers and I didn't skipped them
I just have a low mind with ADHD and Autism that it's hard for me to understand hard
Hi. I'm making a wave system with shop breaks. Would it be best to use an FSM here?
Thinking the states would act like;
Shop-> Wave 1 -> Shop -> Wave 2...
they are shown in the profiler
That seems reasonable
? its better to acknowledge when you are being taught by someone who doesnt know what they are doing so you can try to find better resources. not every teacher is good at their job, this is just an unfortunate truth to life
Are there any tools for FSMs in Unity? Or just old fashion C# apporach/
u can do them with the animator but probably not the best idea
Maybe. Check the asset store. Fsm's are quite simple though. I always just roll my own
Yea was about to say don't suggest the animator, ahahah, been down that road before
I went to a school that is great with game design which did helped me a lot of my first game
lol yeah don't recommend it
Also I and more used to designing
Alright well thanks guys
All I asked that why my texhmeshpro wouldn't work
You probably don't need fsm for wave numbers, just Wave/Shop enum
im not here to be convinced of your schools skill level. You clearly havent been taught the basics first which is a major indicator that something is wrong.
all thats been asked is for you to google how to debug
I know how to debug
So you vote against FSM? Any reason why?
Yes I was, I'm just so forgetful
I would use enums with it too
Trying to find the most effective solution
A lot of things rely on it, it's the main gameloop, so it needs to be robust
so why not use it
the numbers of waves can just be a int
Would that not be just a simple state machine of two states?
I use enums in my FSMs
pretty much
visual studio finally updated and i clicked regen project files, does this mean its regenning project files
I don't think it's much of a help for me when I debug on something even though everything seems to be working
That's not considering the bigger picture... when player death occurs, future proofing for different states, conditional transitions to new levels... etc
That is part of it I guess. Haven't seen it before though
Not sure what you mean?
do you have a regular HDD or SSD?
Even with the current scope, there's at least four states. Shop, wave, death and entry
You've got a null exception in your dev build. You need to go that line and start debug.log and printing everything that's being access on that line. If it's a multiple dot operation then you debug left to right of the line.
you can use events, no real need for a fsn really
fsm
i dont know what either of those mean
if its just wave, shop, wave, shop then its simple enough that you can just use an enum or a bool even (which of course wouldnt be too adaptable). But if you want to add something more complicated in the future then maybe a state machine would be better.
Although I cant really imagine that this would be that complicated, or that anything would really need to read this data. I assume you're just going to load scenes based on this data
Hard disk drive
Or
Solid state drive
I know I got that in the dev build
oh.. nvm then. it shouldnt take long though, you double check if it worked by looking at solution explorer
making sure the solution shows all your unity files
okay
yes so fix it if you know you got it
in the meantime though im getting this error and not sure what it means
Can I actually click on it similar to in console?
not sure
everything seems to be working
But.... you are here for an issue. These argumentative responses are tough to deal with. My 5yo daughter is going through a stage just like this, which is why my patience was so low before haha. Please just understand that we are actually trying to help you. Refusing to look things up, and saying debugging is not worth it is just an absolutely wild way to respond
Just run your game in the editor one time, and show the WHOLE uncropped console
you are defining the class twice it seems
I didn't say debugging is not worth it, I am just saying I tried that, and that everything in the game editing is alright, but in the actual game the pick up with the texhmeshpro is not working
scripts/stats and just in scripts
Well.... I tried I guess.
oh thanks
linedol u have to be willing to recieve help
not just ask how how how
"okay I googled it but I don't understand this part, care to explain that specifically"
if i create an instance of enemystats called slime do i call it enemystats or slime in a script
yeah
u can name it whatever you want
i meant the type
send a picture of what you mean though
like this class uses PlayerStats which is the name of both the scriptableobject itself and the instance of it
The type would be EnemyStats. If your setup is the same from before, slime doesnt need to exist at all
looks like this rn
Your stats ideally shouldnt be different between player or enemy, otherwise your abilities are just gonna have to do the same thing twice.
Your ide still doesnt look configured tho
You probably missed a step
just extent playerstats and enemystats from a base class Stats
ide still notconfigured
what u name the SO doesn't matter
though generally enemies and players should have the same stats so composition would probably be better
then add anything enemy or player specific to the enemy or player class
is the latest version of visual studio editor 2.0.22
thats the package version
did you close vs before and do the Regen Project files?
screenshot the Solution Explorer window in VS
i was updating vs so it closed before i clicked regen project files
but yeah still not working
oh that worked
so should i make an abstract stats class for playerstats and enemystats to inherit from
what differences are there between player and enemy stats? this could all just be under 1 script with no inheritance
read what I said above
about maybe avoiding inheritance
i dont really follow from your message why i should avoid inheritance
are you saying i should keep any shared stats in the abstract stats class
you should have a stats field in your overall player class as well as your enemy class
avoids all the inheritance
so like public class Enemy { Stats stats = new Stats() ...}
i see
and then you can define your stats however you like in the constructor
stats could be a dictionary between enum and float for example, thats what I do
should stats also have shared methods
like add this to stats.cs
public bool damage (float amount) {
if (amount > health) health = 0;
health -= amount;
return true;
}```
well depends the route you go
but if your stats are super simple like health damage, etc
sure
hm ok
if you went the dictionary route, it would be more complicated overall but more robust if you wanted more complicated stats
should i build the enum class into the stats class
alright
wouldnt make a difference though
just more annoying to access since you would have to do Stats.Stat.Health or whatever
yeah makes sense
when getting a tile from a tilemap inorder to work on it
do you get the type Tile or Type TileBase?
what do you mean work on it
all tiles inherit from tilebase
just use the GetTile function also, it returns a tilebase
like rotate or remove collider of that specific tile? or check if theres tile around it
yeah use the GetTile function from your tilemap
yeah thank. i think i meant to have a list of tile but idk i should use tile clas or tilebase class
read the documentation on tiles, it should make sense https://docs.unity3d.com/ScriptReference/Tilemaps.Tile.html
all tiles inherit from tilebase
i read it and still alil confuse of how the two are different to eachother
basically if you want to make your own kinds of tiles, you would inherit from tilebase
Tiles are unities tiles and what you place with the tile pallete etc
oh i see, i think i kinda get it now
public class Stats : ScriptableObject {
Dictionary<StatNames, float> stats = new() {
{ StatNames.Health, 100 },
{ StatNames.MaxHealth, 100 },
{ StatNames.Attack, 10 },
{ StatNames.Defense, 0 },
{ StatNames.Mana, 100 },
{ StatNames.MaxMana, 100 },
{ StatNames.Magic, 10 },
{ StatNames.Resilience, 0 },
{ StatNames.Speed, 3 },
{ StatNames.SprintMultiplier, 1.5f },
{ StatNames.JumpHeight, 3 },
{ StatNames.Stamina, 100 },
{ StatNames.StaminaRegen, 0.25f },
};
Dictionary<StatNames, bool> conditions = new() {
{ StatNames.Healing, false },
{ StatNames.Recharging, false },
};
}```
i have this right now but if i wanted a player to have say healthregen id just set it in the player itself?
and if i wanted to edit speed id do like stats.speed = 12?
I would not make stats a scriptable object
just inherit from Dictionary<StatNames, float>
and then u can make whatever functions u want
good for base stats template but not for mutable data
ic
you can then fill the dictionary in the constructor
and then change the values for the stats within the start function of your player/enemy
use SerializableDictionary 😛
GenericDictionary ❤️
yeah if you want to be able to change the dictionary within the inspector, use one of those from the asset store
since unity can't serialize dictionaries
public bool damage (float amount) {
if (amount > stats[StatNames.Health]) stats[StatNames.Health] = 0;
stats[StatNames.Health] -= amount;
return true;
}```
is this the right way of doing it
either works id assume
yes that should work granted you have Health in your dictionary
alright
you should fill the dictionary with all the enum values in the constructor
you can do it like this public Stats() { foreach (Stat stat in Enum.GetValues(typeof(Stat))) { Add(stat, new StatValue(0)); } }
whatever your names are
oh ok
Mornin' all,
I may just be tired but I'm having an issue and I can't see what's wrong.
I'm using pretty much the exact same code on in Two seperate scripts to create a public list (on each).
https://pastebin.com/VNGnqAaz
This one acts as expected and appears in the Inspector (First Image)
However, this one.....
https://pastebin.com/RcgBpZ9T
Doesn't show the public fields in the inspector (Second Image), and I really can't see why.
Am I just being a moron? lol.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
is [Serializable] above your Wave class?
EnemyInWave is not [Serializable]
Typical. As soon as I posted I saw what was wrong. lol.
I missed the system serializable
<------- 6am moron. lol.
lol
something went wrong
oh wait im bad
i forgot to instantiate stats
nvm still same problem
you shouldnt have a stats field in your stats class
your stats class already is a dictionary itself
it inherits from it
oh
oh didnt even see that lol
and personally i wouldnt have conditions within your stats class
yeah that makes sense
thats more of a state machine typoe of thing
this is a huge rabbithole tho, be cautious
i just recently went down it and finally got my stats/ability system in a working state weeks after i started
damn
keep if simple if your game is simple
well ive done all but whats an easy way of setting all of those values when i make a new instance of stats
manually within whatever class has a Stats field
thats kinda annoying i quite liked this interface
you can do that, but only for "max stats"
it gets a bit messy when you start changing those midgame
oh
a lot of people are stringint about not changing SO's during runtime but it can work
with stats though I dont really recommend it
okay
though you can do that still
have a seperate Stats field in your Player/Enemy class that holds the base stats
then at start, it would add all those values to your real stats
the problems happen during build
well only if you think SO's are a way of saving data
to modify this in the inspector, you would need to have a serializable dictionary
from the unity store or github
oh so the thing you mentioned
yea
ok ill get that
so you could have a scriptable object called like EnemyData that has Stats on it
where would make all your base stats
then plug that into your enemy class and copy all those base stats on start
does it run stuff if i put an onstart function in it
thinking about how to instantiate the base stats
what do you mean?
like rn the stats are all 0
what is "it"
the playerstats and enemystats classes
when you do Stats stats = new Stats()
that calls your constructor
that adds all the stats
yeah but rn theyre 0 and i want to make them not 0 when i start
on your scriptable object?
yeah
so either hardcode it or use genericdictionary
what does genericdictionary change
no that is only if you are changing a scriptable object during runtime
inspector is not runtime
ic
the whole purpose of scriptable objects is to define everything in the inspector
and use it as a data blob
basically
okay got it
like this is of my SO's
for reference
all of those stats are copied into the enemies empty stats when the enemy is spawned
oh ok
Hi, is this where I can ask for Unity-related help?
code
so to install this i just need to drag and drop both cs files into the assets folder?
UmbraGlobe, would you be able to help me as well?
with code sure
actually i think with GenericDictionary you can just copy those files
read what it says mainly
i was adding by git link and like it loaded for a split second but i didnt see any change so i might just copy the files
yea go for it
oh i didnt read console
My enemy class is a prefab and I'm trying to hook a slider onto this enemy. I've instantiated the healthBar object but calling this function yielded that error. Do you think it has to do with the fact that the enemy class is a prefab, therefore is not instantiated?
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
how do you assign healthBar
do i have to put the files in the same folder as my stats stuff or can i keep it in the main assets folder
u can put it whever
oh ok
though one of them needs to be in Editor
public HealthBar healthbar; (as a field in the class)
oh
Qang post ur full code
a powerful website for storing and sharing text and code snippets. completely free and open source.
are you assinging healthbar in the inspector?
Please let me know if you'd like the Health class too, it's really short
no, it's one of the class variables in Enemy class
look at your enemy class on the gameobject
is Health not assigned
public HealthBar healthbar; does not instantiate anything
this is not assignment
see "None"
None
ah ic
put your healthbar on your enemy too
then drag it in
assuming Health is a monobehaviour
Hello unity people!
I am doing a research project, and I have a level with a script that reads/writes to a json. These functions works great when first loads, but restarting the scene causes an error "NullReferenceException: Object reference not set to an instance of an object
updateText.DisplayMessageWithoutLearningMoments (updateText+DialogueEntry entry) (at Assets/updateText.cs:348)"
This is really confusing because the object that is erroring is instantiated according the unity runtime. Is there something simple I'm missing?
I'd be happy to give more context/code just don't want to ramble on lol
Yes Health is a monobehaviour, it seems to hook onto the Enemy object but now my Health class yields the same error.
line 11 is a slider, which it seems to have...
same thing with Slider
when you write public Slider slider, it is not creating an instance of it
rather creating a null field that you can assign it to
in this case, in the inspector
ic, it's declaring it
Yeah, this is my first time using c# and doing game dev
so to make an instance of something you would do public Thing thing = new Thing()
I already have a slider in the inspector of my Health object
with monobehaviors, you typically dont do this
yes you need to assign it
so either in the inspector or by calling GetComponent in start
It was already in the inspector when the error popped up
healthbar needs to be on the same prefab, then apply changes
your sprite renderer and E are null
that will be an issue as well most likely
but whever your class called Mana is
doesnt have Slider assigned
Uh sorry, I dragged the wrong thing in. But now I can't seem to drag the Health object into this slot. Ignore e, I was testing some stuff out. And both Health and Mana have sliders assign to them. I moved the health and mana bar to the same prefab as well.
this?
It just has a slider component that controls the fill object
your field is of type HealthBar
- green and Bold text, btw means changes havent applied to the original prefab
your healthbar doesnt have the healthbar component
Do you mean this?
Yeah... I was figuring out how to do that lol
oh yeah that's on my mana script, brb 1 sec
anything you see like that you can right click and there is Apply to prefab somewhere in that context menu
I applied it to prefab and I switched the HealthBar script over to the Health object
Healthbar also isnt applied to prefab and slider field
ah mb
you're good 🙂
make sure all of your fields dont say none
I'm not sure what to put for Handle Rect, is it fine to leave it empty?
yes that is fine
im diving into state machines again bc im getting rusty in 3d now and need one for movement. what are all the types of state machines? finite, hierarchical, somethin and somethin
And for some reason, I still can't drag the Health object into the slot
start simple, use an enum and some switch statements
get into more complex ones if the project requires
does Health have the Health script on it
I found that one good series of state machine tutorials, but he fucks up each tutorial and then the next one he just fixes his current one. I want to just use the end result, but he literally throws a script out each tutorial
I went thru it before, and have one built already, but its not modular, i cant use it without ripping hair out
unless u are doing some complex AI or something just use enums
it has a health bar script, which looks like this.
this tutorial was pretty interesting though I dont fully understand it lol https://www.youtube.com/watch?v=NnH6ZK5jt7o
In this video, we're going to build a flexible and efficient object-oriented state machine in Unity using C#. The days of using an enum state machine are OVER! This tutorial covers everything from defining states, implementing transitions and predicates and moving between animations using code, all with SOLID principles and the State and Strate...
I havent learned too much about enums, just that they arent very scalable
it is pretty advanced
depends on your use case
it more depends on your state change logic
people tend to overplan
if you have alot they can become combersome
Okay ill give it a go. I just need air, ground, idle walk and run in that order super super sub sub sub
i like the KISS principle the best
yea, i did try it that way. But once i needed more functionality and more states, it became kinda meh
Your field on Enemy is of type Health, you have a HealthBar script
figure out how many you will need ahead of time no
i went from all in one script, to 3, to finite, a halvesie, and now i forgot it all haha
ill do some research and watch the vid thanku
you're trying to over-optimize / over engineer too early I think
beware that video is advanced and for robust systems
i dont recommend it if you are just doing idle walk etc
seems like the animator would work lol
mb I made two scripts before and removing them doesn't delete it for some reason. I added the Health script to the Health object
even adding an extra enum entry wont be a big deal wit ur usecase
so does it work now?
I was also going to have like a UI store system, a working station, storage, customer interaction, and economy... i figured itd be useful haha
thats a good idea 😮
dont need to overcomplicate it
Oh my days, it finally works! THANK YOU SO MUCH, YOU'RE A SAVIOUR. I've been trying to figure this out for hours now haha, this prefab and object stuff is kind of confusing
tysm to u and navarone, u guys are the best
haha yeah np, Health and HealthBar were completely different scripts so you were trying to put x into y basically
its not so much about overoptimization.. but i just want to learn better methods than what im using. Atm i cant really build games with what i know. And its not alot if you dont include if statements
I see okay, how would you go about creating multiple instances of an object, each with it's own unique healthbar?
its important to just get a result working
iterate and optimize is always an option later
by instantiating the prefab
if you set up everything correctly it will all be seperate
Ah okay, I'll test it out tomorrow. Thanks
np
@vale karma Its like you're trying to buy a chainsaw to slice some bread lol
just cause its powerful its not always the right tool for the job
that bread better be the sliciest bread
it will be reduced to crumbs lmao
f it ill do it without one, and go until it hurts
fsms are rarely needed unless u are doing some sort of AI or movement atleast in my experience
atleast super robust ones
just use enums for the most part
yeah and if youre getting complex with substates mind as well use Behavior trees
loooking at GTA3 source code the other day , the enemy AI is only a statemachine switch statement with like 10 enums lol
I just saw a breakdown of that the other day too haha. It was wild the amount of hardcoded and random stuff they used
hey if it works it works right?
on limited hardware too, insane
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Oooookay, so I'm beginning to dislike lists. lol.
I'm generating a new list 'per wave' of enemies using the following.
I am now struggling on adding my enemy items to said list (the public 'AddEnemyToWaveList' method).
The thing I'm struggling with is what to pass in for the EnemyInWave waveList from the script trying to access this method.
This is the line that covers that. I think I'm right in saying that I need to take 'currentWave' which is an int (as I'm using it earlier on with .ToString() to name the generated list.
GameManager.Instance.enemyManager.AddEnemyToWaveList(GameManager.Instance.currentWave, enemyID);
Would anyone be able to give me a clue please? 😕
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
does anyone have an issue with reverse engineering a mechanic? It seems like I can say "click on card, flip it over, pick another card, flip it, check if they match, if so , win, if not lose" but then i go to code it, and instantiating prefabs of cards with front and backs on a grid layout with mechanisms to change images and know if another one matches it and when to check that, how many times you can do all of this before game over... bro its a simple card game why am i crying XD
i tend to get locked up in doing loops that recreate code i already made in a different way
takes time and repetition to hone your own workflow
i stopped trying when i jumped from delegates, actions, func, to scriptable objects.. my heart hurts
yea, im just complaining. im coding too hard or too boring
first thing, you are using start in a non Monobehaviour class? is that intended?
if not it will not be called
also your functions that make a list should just return a list
hi, I wanted to know, I have two objects which have collisions and I would like to put them together and make it so that if we move one, the other follows, do you have any ideas?
Hmm? EnemyManager is a Monobehaviour Class, the EnemyInWave class is 'embeded' inline.
you have a Start function in EnemyInWave
this does not get called unless u explicitly call it
parenting or maybe joint ?
Follows how? Copies the change in position? Or moves towards the first object?
so ive changed stats to a genericdictionary but when i look at inspector it hasnt added a dictionary thing, did i do something wrong
oh wait
send your whole file please, i think im getting it confused since its cut off?
No I don't.
yes, my bad
so you have the EnemyInWave class defined within another class?
that is not in that code snippet?
Ah my bad, I didn't realise I'd cut off the top.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
please use the sites from the bot message for code, this site makes code almost impossible to read on smaller screens
I would like it to be the RAM of a computer which is on the motherboard slot and jsp how is that possible, I would like to take it and resume (the RAM) at any time
Okay, sorry. First time it's been mentioned. 😕
whos the genius that made this css
im confused the purpose of making a EnemyInWave class if it just holds an int
he copies the movement
do you need it to be passed by reference?
tbh, that's a holdover from an earlier version of the code.
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
For easier reading. 🙂
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
what exactly are you trying to achieve with this script and whats happening instead
yeah i am confused as well
is this just for the number of enemies in the wave?
or does enemyID correspond to something
if so shouldn't your list just hold some Enemy class?
One sec fellas, typing the explanation. 🙂
make sure all all of the parts of the dictionary have [Serializable]
where
put [Serializable] above the class header
oh ok
So, basically I'm trying to keep a track of how many enemies exist in a wave. The waves overlap in their spawning so just keeping track of how many enemies exist wasn't working. The idea being that if the player destroys all enemies in a wave, a power up is 'dropped', but if some enemies survive, no drop.
you could have a static int on the enemy class which increments in the constructor
num of enemies
or do you mean all the enemies of an individual wave
so even if there are enemies in a "different" wave, if you kill all of the enemies in the previous wave the powerup drops
Tried that, but as the Waves overlap (wave 2 starts before wave 1 has 'finished' the numbers don't work.
Gimme a sec
you could have an ID on each enemy that when the next wave starts, gets incremented
then on every enemy death, will check if your list of ALL enemies has no enemies with that associated ID
Why dont you have a list of a wave class and that wave class holds a list of the current enemies? Each enemy could call that wave reference to tell that it got destroyed for example
and then teh wave class calls the gamemanager or what not to tell, all enemies dead, drop that power up
yes that would work, just have a callback when an enemy dies for the Wave class to check if its list.count = 0
As every enemy is already an instance inside that list, you can just easily remove it with the reference and update the whole game state
Okay, here's a little gameplay vid that should demostrate a bit better.
Here is my 'Spawn Manager'
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
link doesnt work
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Copied the wrong thing. lol.
And this is my current 'Enemy' Script.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I just flew over that script, but already seeing, you call the gamemanager instance to just update manually the count with -1. Thats what I meant. You have to have a reference to your wave to sort things correctly. Just having a major ALL ENEMIES int will fail in so many ways
Oh yeah I know. That's the thing I'm trying to replace with this whole list thing, I just put it back in so I could record the gameplay vid. 🙂
Ah got it. So I sadly dont have the time to go through all the code and write some pseudo code here, sorry. But try to figure out how to get away from manually set integers for waves and counts. Make a list of wave which its .Count property will already give you what you want. If you need a function for all active wave enemies, write a script, that collects all waves and gets a property from them which you can sum up. Get more in the object oriented direction for this case.
at the beginning of a level, you should perhaps set up a list for with every single wave that will be in that level
I do have a Wave class in my EnemySpawner Manager script, so will look at that.
the list of enemies will be contained by a Wave
and when the enemy dies, it will remove itself from the list, then check the Count of the List<Enemy> within the wave
Actually you could use a scriptable object for your waves too, if you dont have already. If you dont want a fully dynamic endless gameplay but set the waves for a level yourself
it seems like your levels are determined by the song so could you randomly generate all the waves at level start?
or do you need to have them adjusted on the fly
Each level is different numbers of enemies/waves, everything is dynamic based on a random song that is playing. The number of waves is dependant on the length of the song and the 'paths' and 'formations will all be random per wave.
okay so it doesn't need to change during the level itself
AH good to know. Sorry, kinda jumped in this discussion. Can you elaborate your actual issue once more for me, please?
Well yeah it does, every time a wave is created, the wave picks a random Path and a Random formation (the grid), formations will be of differing 'cell' counts etc.
so there are a few ways you could it do it. you could generate a List<Wave> which each Wave contains a List<Enemy> and every time an enemy dies, it has a callback to the wave that it in to remove itself from the wave and check the count
and then when each wave appears, will add a new Wave to the list
Basically, I need to keep track of how many Enemies exist in a given wave. At the 'end' of the wave (when they fly past the camera) there is a check if any of that wave have survived, the player gets nothing. But if the number of Enemies in that wave hits 0 before the 'end' (the player has destroyed all of them) then a power up drops.
Okay, so what I suggested and umbraglobe said above stands as a solution. When you create a wave, give the enemies of that wave a reference to that wave and when they die, they just callback to the wave and reduce the enemies. And then on your wave calss just have a bool return if your enemy count is 0 = completed
and if the wave ends, it will also be removed from the list, and generate no power up since all the enemies will just be deleted with it
This is pretty much what I was trying to do (Each wave generates a new list using currentWave from the GameManager as it's name, and then added each enemy to that list. Was just stuck on what to passover to the 'add enemy to new list'
method.
dont do it with a bunch of ints
just hold A list of waves which holds a list of enemies
have a Wave field in your enemy class that gets assigned when the wave is spawned
and on death will call back to the wave to remove itself from the list
GameManager.Instance.numberOfEnemies = 0;
This line already kills the option to determine individual waves and enemies. Just make your currentWave a function AddEnemy() or something and use that inside the wave class.
personally i would try to avoid relying on GameManager so much
have the GameManager call SpawnWaves, then your wave system handles itself
its bad when both classes are dependent on eachother
typically your game manager should be responding to events sent by your systems and responding accordingly to reduce dependencies
Yep, cleaning things up might help in the overview. Make your wave a single file and detach it from the gamemanager. Its more important than to be a little child in your gamemanager 😉
My head hurts. LMAO
I can imagine 😄
Seriously appreciate the time and input though guys, thank you 🙂
So, first, take everything that is related to a Wave and put that in your extra file class Wave.cs
its better to think backwards when designing systems like this imo, dont design it top down from your gamemanager if that makes sense
make it its own little system and then only the things it REALLY needs it gets from the gamemanager
although you could design it in a way that a gamemanager is not needed
it is ultimately up to you
tbh, most of this is from the Galaga in 3D tutorial course, I've modified it quite a bit to make it work for me though. But never used Lists like this, so yeah, giving me a headache. lol.
lists are nothing but an array with special functions
that reduce boilerplate
insert, contains, etc
And I'll be brutally honest, I like the singleton route simply because I absolute despise referencing multiple classes/scripts etc. I find it very difficult to bug hunt. lol.
One step after the other. Take your time now and refactor your code a bit to clean up dependencies.
singletons are the ultimate bug machine
your game manager should inject all the dependencies into the EnemySpawner/WaveMananger whatever it is and it can function alone from there
then have your wave manager send events that the game manager subscribes to
so imagine like StartWaves(songLength... etc)
Id say, take your time now and use what you read and got on your side. Then come back and see, where youve gotten
Probably drinking heavily. lol.
But yeah, I've got some things to think about. 🙂
Just dont want this discussion to end in a "you could do this or that or here or there" thing 😄 I think we repeated ourselves too much already and kept confusing. So I guess, you know what the suggestions mean and now, happy coding 🙂
Hehehe, the refactoring based on the suggestions is kinda daunting if completely honest. lol.
Just start, dont get afraid of ALL tasks from the start. You will get used to it and looking at it more object oriented, like what can those things do, will make it easier over time 🙂
just refactor completely separately from ur stuff now
so if you mess up or go down the wrong path you still have the code that works
just try some of the things we suggested in some separate class and build from there
Or make a branch if you use github/lab/devops what not
Just spitballing ideas. But, I have this 'sub class' that governs the waves (number of enemies, the path they take and the grid formation to use)
public class Wave
{
public int smallEnemyAmount;
public Path path;
public Formations enemySmallFormation;
}
Could I not use the smallEnemyAmount in some way to keep track?
it would be better to have the wave contain a list of enemies imo
Okay.
since that list gives you the count as well
Okay, I gotcha.
then have a function on your wave that takes in an enemy and removes it from the list
and every time that's called. you could check if enemies.count() == 0
the enemies, having a reference to the wave it's in, could call Wave.RemoveEnemt(this) passing in itself
Okay, yeah makes sense, I understand the theory behind it, now just need to figure out how. lol. Keep looking at the code and have no clue where to start lol. I'm sure I'll figure it out though. 🙂
dependency injection is your best friend when you have multiple layers like this
Hello.
Can someone direct me to a cutscene script? TO make a video before the game starts and one at the end.
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
public bool _isFacingRight = true;
public bool IsFacingRight { get { return _isFacingRight; } private set{
if (_isFacingRight != value)
{
transform.localScale *= new Vector2(-1,1);
}
_isFacingRight = value;
}}
private void SetFacingDirection(Vector2 moveInput)
{
if (moveInput.x > 0 && !IsFacingRight)
{
IsFacingRight= true;
}
else if (moveInput.x < 0 && IsFacingRight)
{
IsFacingRight= false;
}
}