#so just saying GameObject? or would it
1 messages · Page 1 of 1 (latest)
enemyLoop script handles all the list stuff, enemy does nothing but pass itself
@oblique hull
alright, so then just GameObject?
alright so right now its public void enemydetect(GameObject)
you wrote it like this then it gives you underline red
yeah i saw that, so i changed it to EnemyDetect(GameObject)
its still red right now though
did you see the examples on how to declare method parameters?
the structure is always the same when you declare in c#
type name
wait, so what would it need to be in this case? since its not a string for this? GameObject and then a name for it like enemy for example?
yea
show how you wrote it
well its red because you didnt finish writing it..I don't understand did you not see the examples of how the other methods are written
this goes in enemyLoop though
or whatever has the list
oh i have it
i added the brackets okay
and i'll move it to the enemyLoop now
okay i have it in enemyLoop now
write the logic inside, of what you needed earlier
remove from list, check list count
that would be similar enough from that one thing of code i used right?
minus the loop
right
but RemoveAt works with indexes
right now you have enemy
which is of type GameObject
i see
so would i need to make it into an index? or is there something else i can use?
yup just use the List other method of removal
ah i see
would it still be if(enemyList[i] == null) in this case?
just wondering since it doesnt have the for loop
why would you need that or index at all
I mentioned before Lists can shrink
or expand, but this case shrink only
so i would do something like
if(enemy = null)
and then i would use the List.Remove?
break down each step, do one at time start from top to bottom
the top is you are getting enemy from death,
now what next
time start? huh? im not sure how to go about removing from the list I don't know what i would need happen for that, or well, how to write it i guess?
its not even a code thing, you have to like think what you want happening
code comes after you logic your way through it
at this point we have all of the enemies in the list
if you think too much about its a code problem you wont ever solve it.
so, i would need to find a way for it to find out whether or not its destroyed?
if its coming through that method the assumption is , its already ondeath event
think your goal here is your tracking enemies amount..
so seeing if one of the enemies doesn't exist anymore right??
since when they're destroyed they wouldn't still be on the list?
no because destroying a gameobject in the list would only make it null
it would still keep its spot in the list
as null
it would be cumbersome to check the same amount of the list each time if all are null
easier to keep track of the Count , simple integer
so Remove method removes it from list completely
lists count cannot be null..
or well,
its a simple integer
would the count go down if something in the list is null?
nope
thats why an array would not be useful
if you had 20 enemies you would have to loop 20 times each time to check if they're all null slots
that would be inefficent
okay so, what do we need to check then?
well yeah
is none of it making sense at all?
i understand that part
if its 0 then it does that, i understand that
but im not sure how to remove something from the list when it becomes null?
and how do you think it would get to 0
by removing it when it becomes null? but im not sure how to do that
that was the whole point of this an hour ago..
yes i know, and you showed the remove part, but i dont know what if statement to add for it, i dont know how to say
if a gameobject in the list becomes null, then remove it from the list
i understand that once it is empty then i can have if(enemyList.Count == 0 then invoke the function and such
enemy parameter is the enemy about to be removed from game
the gameObject
its one simple line, start there
how does it know that it's about to be removed? or is that for the enemyManager part?
so i start with enemy inside of the method right
enemyManager is irrelevant right now since its empty
righrt
like baking a cake , one ingredient at a time
but i dont know how to start?
like this is what i have right now, i dont know where to start the actual code of it
you have the remove it from the list
okay, so i just put List.Remove?
same as enemyList had method of Count for count
so i would put
Remove(enemy) or so?
well it isnt working i assume?
i mean its red
the thing you said was List.Remove
but i'm not sure what the <t> part is?
so i would need to put
List.Remove so far, but im not sure what else i add onto this?
right
it really is this simple
ok so the next part you already have
think of it in simple words terms
like actions,
if(enemyList.Count == 0)
{ the loop function here}
alright
so i'll put that in
so i have
this
how exactly does enemy know its the one being destroyed? or is that something else that needs to be added?
just added a ;
to the enemyList.Remove line
well how do you currently destroy enemy
if you wanna put that as the script go ahead
as long as you are aware of what script is what
its a bit messy i guess but, i have one object that has all of the prefabs as children of it
so i think it would be fine if i put the enemyLoop script into the enemies object? or would i need to put it into the prefab?
enemyLoop should be in the scene
right now i have enemyLoop on the background, i wasnt sure where else to put it
i did
but im thinking instead of having it on the background, i should put it into the overall enemies object, and then enemyManager maybe into the prefab of the enemy? im not sure
uhh overall i dont know if it matters exactly where it is, but i have the enemyManager script? so im not sure how to go about having 'enemy' be seen as one of the enemies being destroyed
i guess that's the only issue i have right now is that the 'enemy' gameobject, i'm not sure how it is being seen as an enemy that is being destroyed?
can you just screenshot the hierarchy i have no idea what you mean by "on the background"
oh sorry
so i have background, which is just an image on the background of the game
enemies has all of the prefabs loaded in already
and i dont have individual names so it probably looks really ugly, but i have the script on the background object, with the list already filled out
so put enemyLoop on a gameobject called enemyloop
alright, i can do that
but the main thing im wondering about is how to have the enemy gameobject be seen as an enemy thats destroyed?
each enemy has to have script on it, and instead of doing Destroy(collision.gameObject) on laser call a Method inside enemy script that removes from list(already have this in enemyLoop), then runs Destroy on itself
but how would i have it know to do it when the laser hits it?
because when you Hit it you have that reference
and also, so i still have enemyManager, should i put enemyManager on all of the prefabs enemies?
enemyManager is irrelevant right now
okay then, i'll put that into all of the prefabs
and then
im not sure how to make it be known if the laser has hit them outside of the laser's script?
wdym outside the laser script ?
i need to have this script in all of the enemies say to remove itself from the list
and then destroy itself
but it needs something to happen for it to run that
which would be having the laser colliding with it?
yes the laser calls the whole chain reaction
and thats in the laser's script
how would i go about having that occurrence triggering something happening in the enemies script
you just call the method in the trigger
wait
otherway around
yes
and then the enemy's script has the method for removing the enemy from the list and destroying it
and i need to call that method instead of just destroying it right
right
okay let me try and set that up then
the removing from list part you already did inside enemyLoop
just need to call that from enemy Script
wait huh
so i need to
wait
so laserscript needs to getcomponent the enemy's script
as i said earlier, all ur doing is references and calling methods back n forth
well yeah to call the self destroy/ remove from list method in enemy script
enemy's script would need to getcomponent the enemyLoop script
and then the enemy's script would call the EnemyDetect method, and then destroy itself
yeah but GetComponent only works on the gameobject itself or another gameobject you already have refernece to
wdym? uhh
well the laser prefab has the laser's script
and then the empty object for the loop has enemyLoop right now
laser already has enemy's gameObject
so you can do GetComponent on it easily
enemy script needs to store enemLoop inside a variable
well it has the collision.gameObject
right thats the gameObject which can do GetComponent<T>
im not sure how to write that out in this though? im not sure where to put it either
you mean get component ?
i need to sleep soon im just trying to get this figured out its already 4am uhhh
so would it be
GetComponent<enemyLoop>() ?
wait you're starting from the beginning which is the laser
i dont know what i need to connect with what
on the laser script
i need to connect it to the enemy's script right?
laser -> enemy -> enemyLoop
so collision.gameObject is your starting point
from the laser
right
so where should i put the GetComponent part here?
should i just put it right there? or earlier in the code?
GetComponent from the object you hit
and i would put GetComponent<enemyManager>() ?
in the if statement for the collision
you can directly access the method
. operator
would it be GetComponent<enemyManager>(method here?)
or
oh
GetComponent<enemyManager>() . methodname
if you just write GetComponent it will try to look for it on the laser script
do getcomponent on the enemys gameobject
okay
collision.gameObject and then where do i put the getcomponent?
do i attach it onto that?
i dont really understand how to write that sort of stuff
its all a bunch of .
its not that hard
think like a big chain
of pieces of legos that fit
i mean its probably not but i have no idea what . is, we didnt learn any of this coding stuff in that class
so its like
collision.gameObject . GetComponent<enemyManager>() . methodname??
pretty much
okay so i'll put that
except you have to make that methodname ofc or it wont exist
in place of destroying the collision
right
so im going to make a method in the enemyManager script now
and i'll just call it DeleteEnemy
yea
inside enemy script you only need reference to enemyLoop
store it in a variable same as usual
show
why are you putting whitespaces 🤔
also DeleteEnemy is a method
yes?
methods have () 's
oh right
okay
now the only issue is the enemyManager part
oh
wait
i know whats wrong with it
okay we're good now
i had changed the name earlier
and the class and stuff
and i put Manager
when its now enemyScript
okay
that all works
so now
as long as filenames match classes
all its left is a reference from enemy to enemyLoop
since you dont have the gameobject directly no
you can use something like this
https://docs.unity3d.com/ScriptReference/Object.FindFirstObjectByType.html
then call it in awake
the second example is a bit better..
yea..
just don't store it in a local variable, it must be a class level variable
huh?
first declare the variable
yes
okay
not the method just the declaring of the reference
name it somethin that makes sense lol
alright uhh
deletedEnemy or so?
idk
since this is processing that it is deleted
type?
so lets say i go with deletedEnemy idk
i would put
deletedEnemy = FindFirstObjectByType<enemyLoop>() ?
but did you declare deletedEnemy first
would it be declared a gameobject?
no
what would it be declared as?
this?
is that how it would work?
wdym how would it work
is that how it should be
pretty much
public enemyScript deletedEnemy
okay
so i'll put that in
wait
now it has red underlines
because i said that part goes in awake?
do i need to make that?
okay
i'll do that
now its saying it cant convert enemyLoop to enemyScript?
oh
you can use this instead then
https://docs.unity3d.com/ScriptReference/Object.FindObjectOfType.html
same exact thing, slightly different wording
oh
but yeah you need it inside delete method
right oaky
it should pretty much be working after that
how should i call it?
would i just put uhh
enemyloop.EnemyDetect ?
do i need to declare enemy in this?
pretty much
because id need to have it be
pass itself
enemyloop.EnemyDetect(enemy)
what is enemy
what is enemy
you don't need variable names when passing parameters..
so when what would i put?
putting enemy by itself doesnt work because it doesnt exist
the only thing the underline is complaining about
so do i need to declare enemy?
gameObject is the enemy
so i would put gameObject instead
ye
what does error say
object reference is required for non-static field, method, or property
ugh don't use lowercase for classes
shits confusing as hell
classes should be capitalized
yes i realized that but this is what i have in that
so im not sure what variable you mean?
what did you name the class..
the method is irrelevant right now
then you should not be using the class directly in enemy script..
then what do i put there?
as i already said, store it in a variable..
store what in a variable??
wdym store what
enemyLoop
enemyLoop is the script
you named it enemyloop
why did you change it
enemyloop is the script
from enemyLoop
i didnt change it
its always been enemyloop
the filename is enemyloop, the class name is enemyloop
always has been
are you referring to the deletedEnemy part?
ugh alr . always capitalize your classes/filename then
enemyloop. store it in a variable
you called deletedEnemy ??
no?
why are you using enemyloop.EnemyDetect then
thats what i had said before i dont know
wdym called?
wait
yeah? i dont know
so i need to put
i showed you the code
the whole point of doing this
is to use enemyloop through deletedEnemy
if thats where you're putting the reference
im barely awake right now im just tryin gto get this last bit of code through
so should it be
deletedEnemy.EnemyDetect?
since thats the varaible i have with the enemyloop find object of type?
ok there it goes
so that calls enemy detect
so now i just need to put destroy gameobject right?
pretty much
should be
you can check inspector as well if the list shrinks
yes its very simple stuff to do
when you understand this stuff
well the main thing to learn is the basics
maybe if my class actually taught coding instead of just the engine it'd be nice but hmm
but its fine now
coding is important too , but logic is far more useful
try to break down into smaller easier to find bits of problems
im just not very smart with this sort of stuff, kinda realized that way earlier this semester loll but ive made it through the class so far
but thank you
yeah
