I want to make a weapon follow the player after i instatiate the weaponinto the game.
public class BowItem : MonoBehaviour { public GameObject Bow; private Transform Hand;
private void Start()
{
Hand = GameObject.FindGameObjectWithTag("Hand").transform;
}
public void Use()
{
Instantiate(Bow, Hand.position, Quaternion.identity);
Destroy(gameObject);
}
}
Answer by dan_wipf · Mar 25, 2019 at 11:56 AM
you need to set the bow to a parent, i believe in you case that’d be the hand transform => Instantiate(Bow, Hand.position, Quaternion.identity,Hand.transform);
, basically if you choose a parent, the instantiated object always will be in a relative localposition towards the parrents position, means it will folow the parrents position
Your answer
Follow this Question
Related Questions
Game Object doesn't instantiate at Mouse Position 3 Answers
Instantiating random prefabs gives wrong position 3 Answers
Making a 2D sprite look at another object when instantiated... 1 Answer
Jitter when moving around a circular path 0 Answers
C# Photon Networking - Preventing duplicate GameObjects from spawning on Join. 1 Answer