#hi guys can someone help me figure out
1 messages · Page 1 of 1 (latest)
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
ooo
A tool for sharing your source code with the world!
i did a shit job on naming things and its biting me in the ass
where did you learn unity programming from?
this is all so weird
my brother
i have never learned any unity coding
i took coding classes in highschool and uni
this is for an art project
so your brother wrote all of this code?
no like
the server dosent let me say bro
i wrote all this code...
im jamming like 15 different youtube tutorials into one proj
ok and im asking where you learned unity syntax from
and holding it together with my basic java knodwledge
is it that bad
ah ok
it's not bad as much as it is weird
but there are blatant problems
like my knowledge of int bool and float n shit r from java and python
ive looked through the api but its giveng me an aneurysm
plus my mild dyslexia
Instead of using Resources.Load, loading it as a UnityEngine.Object, spawning it as a GameObject, then getting the Enemy component, you should instead just make enemyRef of type Enemy and drag the prefab into the inspector
Ah, wait, actually this is an Enemy so it'd update that prefab reference to a self reference. The Resources.Load might need to stay
just knowing the easy way to do things would help a ton. you are complicating things so much unnecessarily
But you can at least cut out the multiple layers of casting and getcomponent by making it of type Enemy to start
uh... what does updating a prefab reference to a self ref mean
i really wish i could man. unfortunatley im running out of time
do you see the problem here
wait since i destroyed game object it cant create a new object using the game object ref?
my respawn worked fine
Unity automatically replaces references to things within the same prefab with the corresponding references on the instances it creates. Since this presumably is the enemy prefab, dragging in a reference would mean that it would update to refer to itself. Basically, due to a shortcut unity provides to make dealing with prefabs easier, in this specific case you do need the Resources.Load. But you can still just make the variable of type Enemy
Not a problem, Destroy happens and end of frame, and does not return from the function. It'll still spawn an object after destroying itself.
ah my bad. i remembered having problems with this under different circumstances
so how would i fix this
Are you getting your "Player not found" log? Or any errors at all?
nah ur good bro it makes complete sense
i was thinking the same thing
Nothing. That was a problem I realized with my first suggestion, which I then ammended.
just player not found
So then that would be the problem
it def respawns with the player bracket emtpy
Your Find does not get anything
so like... my code... its cooked ;-;
There's nothing in the scene tagged player
Just change your enemyRef to type Enemy and cut out all the casting and the getcomponent after spawning it
like private Enemy enemyRef;?
Yes
dumb question but whats casting..
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/types/casting-and-type-conversions
A tool for sharing your source code with the world!
so would this work better
i might be stupid sorry if i didnt do jack shit to improve it ts is confusing ash
Why are you loading it as a GameObject then getting a component from it
Just get it as an Enemy
then you don't need to get component
er... u might have to hold my hand thru this one man...
im gonna be completley honest im so confused
Instead of loading it as a GameObject. Load it as an Enemy
On that line
You can just replace the word GameObject with the word Enemy
so under cs
Enemy prefab = Resources.Load<Enemy>
this part
("Enemy");
if (prefab != null)
{
enemyRef = prefab.GetComponent<Enemy>();
}
would all be useless?
yes
shit
well thats all i changed
A tool for sharing your source code with the world!
this is the current state
Yes, and as your error states, your issue is there's nothing tagged "Player" in your scene to find.
and unity is saying the object i want to instantiate is null
Oh, you never actually set enemyRef
you create a new variable prefab and then do nothing with it
oh
so like public int prefab?
and then my code will magically work?
this feels like a coconut.jpg
HELP it wont even respawn anymore i hate my life
Why would prefab be an int
You have a variable enemyRef that you spawn a copy of. You need to actually set that to something
what... what would it be...
? how do i se tthat to something
bro i wanna thank you for your help btw i rlly mean it
With =
Why should it exist at all
in Enemy newEnemyScript = Instantiate(enemyRef);?
No, you need to assign a value to enemy ref
i thought i create a new variable prefab and do nothing with it...
This is where you're trying to use it
Yes. Why are you doing that
Why are you making a whole new variable to put this reference in to
instead of using the variable you actually want to put the prefab into
so ... sorry but.. what would this change look like
i deleted the prefab thing
btw
Right now you have two issues:
- You do not set
enemyRefto anything - You are storing the result of
Resources.Loadin a variable that is never used
Think about how these two problems might relate
and how you might reconcile them
i just deleted the resources load part
You are using a variable you never set,
and setting a variable you never use.
how would i set enemy ref to something and where? currently its only used in private Enemy enemyRef which like you said creates the enemy ref as an empty variable
and then
Enemy newEnemyScript = Instantiate(enemyRef);
which creates a new enemy
Which creates a clone of enemyRef
You aren't setting enemyRef to anything
so you are cloning nothing
oh fuck
What prefab are you trying to clone
Enemy
Cool, where do you get the Enemy prefab?
in my resources folder :)
So, you have a variable you want to set to Enemy
and a line where you get Enemy
So why do you not
set that variable
to that enemy
what country are you from by the way
Irrelevant.
hahaha noted
i j dont understand wym
What line of code
is getting the Enemy prefab
from your resources
i had Enemy prefab= Resources.Load<Enemy>("Enemy");
but i deleted it
ill put it back
So, you have a line that loads the prefab from resources
and you have a variable that is supposed to hold the prefab from resources
and you know how to set a variable to a value
so do that
why would that even remotely work
do you have any clue at all what you are doing
or are you just hitting random keys in hopes it works
I literally cannot explain this any simpler
set the variable
no bro
yes basically
that's the simplest explenation
i wont even lie to you
I'm not doing any more of this
Open a book. Literally any book. Finnegan's Wake would probably help you understand more than this right now
I'm out
what i dont understand what the variable would be
private enemy enemyref? as the string variable?
Literally the variable that the error is telling you is null
Instead of never setting it to anything
set it to something
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Figure out what words like "variable" mean
string int bool etc
I can't explain it if you literally do not know what words mean
bro icl if u show me what u mean
i think it would help me understand 1000% percent better
many times
I've told you exactly what to do
and you've done like twelve completely unrelated different things
i understand that but if I lack the fundamental knowledge to achieve the task i feel like its harder to do
This is Sesame Street level.
You have a variable that you never set a value to.
You have a value that you never store in a useful variable.
Put two and two together
enemyRef = Resources.Load<Enemy>("Enemy");?
that solved the respawn but it still dosent fix enemy follow...
did i do it wrong?
I already told you the problem on that one and you literally wrote an error message to yourself to tell you what the problem is
there's nothing tagged Player in the scene
oh
thank u bro
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
do you know why the attack only works in the right direction?