In my Unity project I have 2 "hands" for items that should be placed inside of the images in the left bottom corner and for that I have this code:
...
if (!IsHandOneFull())
{
var obj1 = Instantiate(HandItem1, HandItem1.rectTransform.position, new Quaternion(0f, 0f, 0f, 0f), HandItem1.transform);
obj1.sprite = currentUIItem.GetComponent<Image>().sprite;
obj1.name = currentUIItem.gameObject.name;
obj1.gameObject.GetComponent<Image>().rectTransform.sizeDelta = new Vector2(110f, 110f);
}
else if(!IsHandTwoFull())
{
var obj2 = Instantiate(HandItem2, HandItem2.rectTransform.position, new Quaternion(0f, 0f, 0f, 0f), HandItem2.transform);
obj2.sprite = currentUIItem.GetComponent<Image>().sprite;
obj2.name = currentUIItem.gameObject.name;
obj2.gameObject.GetComponent<Image>().rectTransform.sizeDelta = new Vector2(110f, 110f);
}
and it works like a charm for the second "hand", but somehow it messes up the items(obj1 in code) coordinates in the first "hand" after it is instantiated, so that it isn't in the intendet place but way more left, out of the canvas. Maybe it's because that the 1st "hand"(image) is slightly bigger than the second, but I don't know how to fix it. I don't want to set the coordinates to fixed coordinates(idk if that's the right term but I mean new Vector3(...)), because that could cause problems with other features.