<Unity3D>实例化UGUI中GameObject 并设置它的位置

来源:互联网 发布:新疆继续教育网络培训 编辑:程序博客网 时间:2024/05/29 19:22
</pre><pre name="code" class="csharp"><pre name="code" class="csharp">using UnityEngine;using UnityEngine.UI;using System.Collections;public class ItemInfo : MonoBehaviour {    public GameObject prefab;//预设体    GameObject pre;    void Start()    {        pre = (GameObject)Instantiate(prefab);        pre.transform.SetParent(GameObject.Find("Panel").transform);        pre.GetComponent<RectTransform>().localPosition = new Vector3(50, 0, 0);//设置该物体的RectTransform组件的POS X、POS Y、POS Z        pre.GetComponent<RectTransform>().sizeDelta = new Vector2(160, 211);//设置该物体的RectTransform组件的Width、Height<span style="font-family: Arial, Helvetica, sans-serif;">   </span>    }}


                                             
0 0
原创粉丝点击