C#
C#

help

Root Question Message

benny
benny1/26/2023
❔ enemy player follow

when i make a clone of enemy it uses original enemy position. i need a work around. either a way to get a clones position or someone can tell me im dumb and show me a better way to do this thank
TheRanger
TheRanger1/26/2023
CloneEnemy.transform.position = new Vector2(10, 10);
benny
benny1/26/2023
Thanks I can’t test this now but won’t this just change the position of the spawned clone or am I wrong?
TheRanger
TheRanger1/26/2023
yes, isnt that what you want?
TheRanger
TheRanger1/26/2023
if you just want the position just call it
benny
benny1/26/2023
No the problem lies with the way I make the enemy follow the player it uses the original enemy’s position not the clones position do you know how I could call the clones position instead
TheRanger
TheRanger1/26/2023
CloneEnemy.transform.position thats how u call it
benny
benny1/26/2023
Thanks
benny
benny1/27/2023
keep getting this error msg any idea on how to fix
UnassignedReferenceException: The variable CloneEnemy of EnemyAttack has not been assigned.
You probably need to assign the CloneEnemy variable of the EnemyAttack script in the inspector.
EnemyAttack.Update () (at Assets/Scripts/EnemyAttack.cs:22)
TheRanger
TheRanger1/27/2023
can u show code of that line?
benny
benny1/27/2023
Where gameobject.find(“enemy”)is switched with CloneEnemy
benny
benny1/27/2023
Vector3 AttackDir = (GameObject.Find("Player").transform.position - CloneEnemy.transform.position);
benny
benny1/27/2023
TheRanger
TheRanger1/27/2023
where is CloneEnemy defined? in waves class?
benny
benny1/27/2023
no
TheRanger
TheRanger1/27/2023
where then?
benny
benny1/27/2023
yes sorry wavews
TheRanger
TheRanger1/27/2023
well the error message tells you how to fix it
TheRanger
TheRanger1/27/2023
:awesome:
benny
benny1/27/2023
ok one sec thanks
benny
benny1/27/2023
sorry im confused isnt each instance of CloneEnemy enemy?
benny
benny1/27/2023
oh ok think i got it maybe
benny
benny1/27/2023
please can you spell it out for me im dumb
TheRanger
TheRanger1/27/2023
CloneEnemy has no value assigned to it
TheRanger
TheRanger1/27/2023
it doesn't know which Clone Enemy to refer to
benny
benny1/27/2023
oh ok thanks
benny
benny1/27/2023
life saver
TheRanger
TheRanger1/27/2023
u have to find a reference of the enemy and assign it to the variable example
TheRanger
TheRanger1/27/2023
CloneEnemy = GameObject.Find("Enemy");
benny
benny1/27/2023
i know its a big ask but could i stream in a vc 2 u cause im really not getting it every time i think i am im just dumb
TheRanger
TheRanger1/27/2023
very hard but u can try sending screenshots atleast
benny
benny1/27/2023
ok thanks
benny
benny1/27/2023
benny
benny1/27/2023
TheRanger
TheRanger1/27/2023
is EnemyAttack script attached to a gameobject?
benny
benny1/27/2023
TheRanger
TheRanger1/27/2023
ok so u have 2 Start methods
TheRanger
TheRanger1/27/2023
i think the one in waves isnt being called
TheRanger
TheRanger1/27/2023
because the one in EnemyAttack is being called instead
TheRanger
TheRanger1/27/2023
since EnemyAttack inherits from waves
TheRanger
TheRanger1/27/2023
not 100% sure u have to use Debug.Log for that
benny
benny1/27/2023
oh i was just checking location
benny
benny1/27/2023
is this better?
TheRanger
TheRanger1/27/2023
also
TheRanger
TheRanger1/27/2023
yeah but
TheRanger
TheRanger1/27/2023
you never assigned a value to the field cloneEnemy
TheRanger
TheRanger1/27/2023
you declared a local variable of the same name and assigned a value to it instead
TheRanger
TheRanger1/27/2023
benny
benny1/27/2023
like this?
TheRanger
TheRanger1/27/2023
that affects performance
TheRanger
TheRanger1/27/2023
Unity will always try to find that game object and assign it to the variable every frame
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy