C
C#2y ago
EmoEmu_69

❔ How to use a GameObject's location as the location for Instantiate

Hi so I'm trying to make a projectile, and I want the spawn location to be relative to the location of the player. Thanks in advance!
3 Replies
kakanics
kakanics2y ago
'''Instantiate(gameobject, transform.position+offset, Quaternion.identity);''' A vector3 named as offset is used to change the spawn position and the transform.position spawns the object at the position of the object on which the spawner script sits You can create a variable for the Transform component of player and refer to it in your scipt public Transform player; Public GameObject prefab; Publicn Vector3 offset; Void Start(){ Instantiate(prefab, player.position+offset, Quaternion.identity); }
EmoEmu_69
EmoEmu_69OP2y ago
oh awesome, thank you so much!
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server