Why does the canvas scale factor change when instantiating Prefab?
Hello Guys, so I've been trying to create a scratch-like Program. Basically, you have some moveable UI components, which then, after combining them in a certain area, create a function. After I drop those UI components on this area, the same Objects need to be placed on the position before dragging. I do this by instantiating a Prefab.
But if I now try to drag the new Components, the canvas.scalefactor changed and therefore when dragging the Object is moving more or faster then my cursor.
I'm using the following Code for Instantiating:
public void OnDrop(PointerEventData eventData)
{
if(eventData != null)
{
eventData.pointerDrag.transform.SetParent(FunktionenContainer);
NameFunktion = eventData.pointerDrag.name;
Prefab = (GameObject)Resources.Load("prefabs/" + NameFunktion, typeof(GameObject));
GameObject myPrefab = Instantiate(Prefab);
myPrefab.transform.SetParent(ParentFunktion.transform, false);
myPrefab.name = NameFunktion;
And for Dragging:
public void OnDrag(PointerEventData eventData)
{
Debug.Log(canvas.scaleFactor);
rectTransform.anchoredPosition += eventData.delta / canvas.scaleFactor;
}
In this example my normal canvas.scalefactor is 1.4525 after instantiating the new canvas.scalefactor is set to 1 (might be the default value).
Why does that happen and how could I fix that?
I'd be very thankful if somebody could help me on that!
Thanks in Advance