Question by
Tonba · Jan 20, 2020 at 08:47 PM ·
transformmobileparent-childattach
Attach gameobject to my player on touch and stay in a hold slot made for it
I need my gameobject to attach my player when player touches it. Also i need the object to stay in the posession of player. Trying to make icehockey game and making puck to attach my players stick. Now the puck does not move with the player correctly.
public class Puck : MonoBehaviour {
public GameObject holdSlot;
public GameObject puck;
Vector3 pos;
void Start()
{
holdSlot = GameObject.Find("PuckHolder");
pos = holdSlot.transform.position;
}
// Update is called once per frame
void Update()
{
}
public void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "IceSlyder")
{
transform.parent = holdSlot.transform;
transform.position = pos;
// HERE I NEED TO MAKE THE OBJECT ATTACH TO MY PLAYERS EMPTY GAME OBJECT "holdSlot"
// AND MAKE THE OBJECT A CHILD OF THE EMPTY GAME OBJECT SO IT STAYS IN PLAYERS POSESSION AS PLAYER MOVES
}
}
}
Comment