</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>
}
}
<Unity3D>实例化UGUI中GameObject 并设置它的位置
最新推荐文章于 2022-11-01 23:26:25 发布