#Hastebin

1 messages · Page 1 of 1 (latest)

whole tree
#

Starting a thread

#

so we don't spam the main channel more

#

lemme look

meager schooner
#

Ok.

whole tree
#

So you want this CowboyAnimationScript to refer to teh XR Origin?

meager schooner
#

yes

#

but the CowboyAnimationScript is inside of a prefab

#

not the hierarchy

#

like thsi

whole tree
#

well here's one easy way to do it, from the script that spawwns the cowboy:

#

(I'm assuming the xr origin is the player and you want the cowboys to look at the player)

meager schooner
#

yes

#

the xr origin is like a vr player

whole tree
#
public Transform player; // assign in the inspector to the player object in the scene
public CowboyAnimationScript cowboyPrefab; // assign in the inspector to the prefab from the Project window

void SpawnCowboy() {
  CowboyAnimationScript newCowboy = Instantiate(cowboyPrefab);
  newCowboy.LookObject = player;
}
#

Again this would be in the script that spawns the cowboys

#

the spawner script

#

basically you just keep a reference to the player here, and share that reference with the newly created cowboy instances as you spawn them.

meager schooner
#

k that could work

#

but i am spawning them in waves so i have something like tihs already Instantiate(waves[currentWave].GetCowboySpawnList()[i], FindSpawnLoc(), Quaternion.identity); so if i did that then i would get rid of the waves[currentWave] bit so it would not work

#

@whole tree

whole tree
#

it's the same thing

#

take the result of Instantiate

#

assign the reference to it

#

YOu're probably using a GameObject reference which makes your life harder here. I recommend switching to a CowboyAnimationScript reference directly. Otherwise, you'll need to call GetComponent on the returned object to get the script, then assign the reference

meager schooner
#

I tried this but it gives me this error, but i dont understand because we assigned it in the code

whole tree
#

you're now creating a whole separate instance

meager schooner
#

oh k.

whole tree
#
CowboyAnimationScript newCowboy = Instantiate(waves[currentWave].GetCowboySpawnList()[i], FindSpawnLoc(), Quaternion.identity);```
#

however as I said earlier

#

you probably used GameObject as your prefab reference

#

so you either need to change that to CowboyAnimationScript or do this:

GameObject newObj = Instantiate(waves[currentWave].GetCowboySpawnList()[i], FindSpawnLoc(), Quaternion.identity);
CowboyAnimationScript newCowboy = newObj.getComponent<CowboyAnimationScript>();```
meager schooner
#

like this

#

if i replace the g in getComponenet with G

whole tree
#

yes

meager schooner
#

oo it working

#

tysm

whole tree
#

No problem. Do you understand what the code is doing?

meager schooner
#

yes

#

however

#

the cowboy is nolonger stopping to punch the player when colliding

#

it is just continuing to walk

whole tree
#

well that's a completely separate issue

meager schooner
#

yes

#

nvm i fixed it