#Hastebin
1 messages · Page 1 of 1 (latest)
Ok.
So you want this CowboyAnimationScript to refer to teh XR Origin?
yes
but the CowboyAnimationScript is inside of a prefab
not the hierarchy
like thsi
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)
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.
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
why would you get rid of that
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
I tried this but it gives me this error, but i dont understand because we assigned it in the code
nonono
you're now creating a whole separate instance
oh k.
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>();```
yes
No problem. Do you understand what the code is doing?
yes
however
the cowboy is nolonger stopping to punch the player when colliding
it is just continuing to walk
well that's a completely separate issue