I want to approach a game object in game and have it attach itself to the other game object. Like a player approaches the weapon and it gets picked up to be used.
1 Answer
1Well, if you want to detect when a player enters the bounds of the object’s collider, use OnCollisionEnter. To parent one object to the other, use the collider detected in the OnCollisionEnter event in conjunction with Transform.SetParent().
For example you could use this with the object that would be colliding with the one that should start following.
void OnCollisionEnter(Collision col)
{
col.transform.SetParent(this.transform);
}