Newboy11
Newboy11

Reputation: 3136

Size of prefab when spawning in panel is too small

I'm spawning prefab in a panel but it's size is too small like a dot but when I spawn it outside the panel there's no problem . Please check below image and code

enter image description here

public class RedKeyShapeSpawn : MonoBehaviour
{
    public GameObject redshapes;

    void Start()
    {
        GameObject redkeychild1 = Instantiate(redshapes, transform.position, 
transform.rotation) as GameObject; 
        redkeychild1.transform.SetParent(GameObject.FindGameObjectWithTag
("ShapePanel").transform, false);

    }


    void Update()
    {

    }
}

RedKeyShapeSpawn script is attached to RedKey1spawn object

Upvotes: 2

Views: 775

Answers (2)

Shadow
Shadow

Reputation: 4006

The culprit of this issue is likely the transform of the ShapePanel. If the transform of that object is not 1x1x1 then any objects added as a child of the panel will be affected by it.

Consider making the prefab a child of the panel, and rescale it accordingly. Then when you spawn the prefab and add it as a child of the panel, the scale of the RedKey should be as you expect.

Upvotes: 1

LiefLayer
LiefLayer

Reputation: 1073

Problem is that when you spawn you object inside the panel it will inherit the parent position and use that as a reference (x,y and z are relative). You should be able to solve this problem if, for example, your panel in in the origin (0,0,0) or if you set an absolute position in your code.

PS. Same thing with rotation and scale

Upvotes: 1

Related Questions