✅ 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
66 Replies
CloneEnemy.transform.position = new Vector2(10, 10);
Thanks I can’t test this now but won’t this just change the position of the spawned clone or am I wrong?
yes, isnt that what you want?
if you just want the position just call it
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
CloneEnemy.transform.position
thats how u call itThanks
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)
can u show code of that line?
Where gameobject.find(“enemy”)is switched with CloneEnemy
Vector3 AttackDir = (GameObject.Find("Player").transform.position - CloneEnemy.transform.position);
where is CloneEnemy defined? in
waves
class?no
where then?
yes sorry wavews
well the error message tells you how to fix
ok one sec thanks
sorry im confused isnt each instance of CloneEnemy enemy?
oh ok think i got it maybe
please can you spell it out for me im dumb
CloneEnemy has no value assigned to it
it doesn't know which Clone Enemy to refer to
oh ok thanks
life saver
u have to find a reference of the enemy and assign it to the variable example
CloneEnemy = GameObject.Find("Enemy");
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
very hard but u can try sending screenshots atleast
ok thanks
is EnemyAttack script attached to a gameobject?
ok so u have 2 Start methods
i think the one in waves isnt being called
because the one in EnemyAttack is being called instead
since EnemyAttack inherits from waves
not 100% sure u have to use Debug.Log for that
oh i was just checking location
is this better?
also
yeah but
you never assigned a value to the field
cloneEnemy
you declared a local variable of the same name and assigned a value to it insteadlike this?
that affects performance
Unity will always try to find that game object and assign it to the variable every frame
you only need to assign it once
still getting same error msg and the prefabs wont spawn in
use Debug.Log to make sure cloneEnemy isnt null
ok
well
if the prefabs dont spawn
it says its null
ur trying to Instantiate/Clone a null object
still says null but the prefabs spawn in and the original follows player
so the prefab got spawned?
where does it say its null?
and the 4 game objects that got spawned? what are their names
show screenshot of ur unity where they got spawned
null
UnityEngine.Debug:Log (object)
EnemyAttack:Update () (at Assets/Scripts/EnemyAttack.cs:24)
they are called enemy(clone)
all of them have the same name?
yeah
not like
Enemy(Clone)(1)
Enemy(Clone)(2)
Enemy(Clone)(3)
Enemy(Clone)(4)
?all different names now i removed wrong thing
no wonder this returned null
still getting that
do something like
GameObject.Find("Enemy(Clone)");
or u can just assign the variable in the CreateEnemy methoddo
GameObject.Find("cloneEnemy1");
thenyeah that one prefab now follows me how could i change "cloneEnemy" to get whaterver name it needs?
access the .Name Property of the GameObject and change it
like this?
ur trying to change their names right?
u do
cloneEnemy.name = "whateveryouwanttonameit";
im trying to make it so whatever name it is gets the location of that clone
so trying to set cloneEnemy to any name of clone
if that makes sense
GameObject.Find("cloneEnemy3").transform.position
to get position of cloneEnemy3
im not sure what that meanslike that instance so it can just look at itslef and be like im at this positon so like when you have a an object and it knows its that object so when it calls a method and the method know that its that one
look at itself?
i dont really understand what ur saying
dont worry man im gonna assume there isnt a way to do what i want to do thanks for all the help
if english isnt ur first language can u try using google translate atleast?
what is going on in here💀
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.@TheRanger don't know if you remember this but easiest fix ever Vector3 AttackDir = (GameObject.Find("Player").transform.position - transform.position); used trandform.position which will get the position of whatever it is talking about dont need a use object name