if (Input.GetMouseButtonDown(0))
{
Vector2 outVec;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, Input.mousePosition, canvas.worldCamera, out outVec))
{
// Debug.Log("转换后的屏幕坐标: " + outVec + "鼠标坐标" + Input.mousePosition);
int idx = Random.Range(0, LeiFen_BoxPrefab.Length);
GameObject ShuiBoWenobjClone = Instantiate(LeiFen_BoxPrefab[idx]) as GameObject;
ShuiBoWenobjClone.transform.parent = LeiFen_BoxFuWuTi;
ShuiBoWenobjClone.transform.localPosition = new Vector3(0, 0, 0);
float idx1 = Random.Range(float.Parse(ConfigTest.dic["设置"]["冰裂最小值"]), float.Parse(ConfigTest.dic["设置"]["冰裂最大值"]));
ShuiBoWenobjClone.transform.localScale = new Vector3(idx1, idx1, idx1);
ShuiBoWenobjClone.GetComponent<RectTransform>().anchoredPosition = outVec;
}
}
LeiFen_BoxPrefab 是要克隆的物体
LeiFen_BoxFuWuTi 克隆物体的父物体
当鼠标左键按下时,该代码将从预设的LeiFen_BoxPrefab中随机选择一个物体进行克隆,并将其作为子物体添加到LeiFen_BoxFuWuTi下。克隆的物体位置基于屏幕坐标转换,并具有随机缩放值,范围由配置文件定义。
1135

被折叠的 条评论
为什么被折叠?



