I’m making a 2D game and I’m trying to make a power up that spawns out a shield on the player. It’s supposed to be attached to the player, so when the player moves it will be attached to the players position. I’ve managed to instantiate the shield but it only spawns on the players position and is not attached.
How can i attach the shield to the player? Greatful for any help I can get, you guys are the best!
using UnityEngine;
using System.Collections;
public class PickUpScript : MonoBehaviour
{
public GameObject shield;
void OnTriggerEnter2D(Collider2D col)
{
if(col.gameObject.tag == "PowerUp1")
{
SpawnShield();
Destroy(GameObject.FindGameObjectWithTag("PowerUp1"));
}
}
public void SpawnShield()
{
Instantiate(shield, GetComponent<MoveScript>().character.transform.position,
GetComponent<MoveScript>().character.transform.rotation);
}
}