I’ve got a Player object and a Weapon object on the scene, and I want the weapon to become attached to Player when the player touches the Weapon.
void OnTriggerEnter2D(Collider2D other) {
transform.parent = other.transform;
}
this is the trigger code on the Weapon class. When the Player touches the Weapon, it triggers the OnTriggerEnter2D function, and when i rotate the player the weapon turns around aswell. However, the x and y of the weapon don’t change when the player moves around.
I’ve tried many variations of this, such as:
this.transform.parent = other.transform;
transform.parent = other.getComponent<Transform>();
All of them have the same effect. What am I doing wrong?