I was adding animation to my player’s sword and noticed it would shrink when I rotate it. I was able to fix this by giving it an empty gameobject parent and setting the parent’s scale to the sword’s scale of 2,1,2 and the sword itself to 1,1,1. However now I’m using a script to instantiate the sword as a child of the player’s hand and the shrinking issue has returned. Furthermore the parent is created with a scale of 4,1,4 making the sword stretched.
This is my code for instantiating the sword:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerWeaponController : MonoBehaviour {
public GameObject PrimarySlot; //The player's hand
public GameObject EquippedWeapon { get; set; }
IWeapon currentPrimary;
public void EquipWeapon(Item itemToEquip)
{
if (EquippedWeapon != null)
{
Destroy(PrimarySlot.transform.GetChild(0).gameObject);
}
EquippedWeapon = (GameObject)Instantiate(Resources.Load<GameObject>("Weapons/" +
itemToEquip.ItemCode), PrimarySlot.transform.position, PrimarySlot.transform.rotation);
EquippedWeapon.transform.SetParent(PrimarySlot.transform);
currentPrimary = EquippedWeapon.GetComponent<IWeapon>();
}
public void LeftAttack()
{
currentPrimary.LeftClick();
}
}
Let me know if anyone needs more information. Thanks for the help.