Prefab在unity中比较方面,可以动态的添加,在添加的时候可能会遇到这样的问题,我已经调整好了大小,位置和旋转了但是我添加进来之后还是原来的没有变化。下面的代码就可以帮你解决这个问题。
using UnityEngine;
using System.Collections;
public class Item1 : MonoBehaviour {
public GameObject Object1;
public GameObject Prefab01;
public GameObject parentObject;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnClick()
{
//print("1234");
Destroy(Object1);
GameObject clone=(GameObject)Instantiate(Prefab01);//添加prefab
clone.transform.parent=parentObject.transform;//设置为某个物体的子物体
clone.transform.localPosition=Vector3.zero;
clone.transform.localScale=Vector3.one;
clone.transform.localRotation=Quaternion.identity;
}
}