unity--设置父物体与Transform

错误示范:(坐标会乱掉)

1

2

3

4

5

6

7

public static CardBase Create(Transform parent) {
        GameObject go = (GameObject)Instantiate (Resources.Load("Prefabs/normal/CardBase"));
        go.transform.parent = parent;
        go.transform.localPosition = parent.localPosition;
        go.transform.localScale = parent.localScale;
        return go.GetComponent ();
    }

正确示范:

1

2

3

4

5

6

7

public static CardBase Create(Transform parent) {
        GameObject go = (GameObject)Instantiate (Resources.Load("Prefabs/normal/CardBase"));
        go.transform.parent = parent;
        go.transform.localPosition = Vector3.zero;
        go.transform.localScale = Vector3.one;
        return go.GetComponent ();
    }

你可能感兴趣的:(Unity)