您当前的位置: 首页 >  unity

云小川

暂无认证

  • 4浏览

    0关注

    78博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity 在2D区域 随机生成2D物体 并且不重叠

云小川 发布时间:2022-03-08 17:38:37 ,浏览量:4

一 2d区域为父物体(涉及到UI变动自适应等)

 2d区域和2d物体 Itme的锚点设置  看自己  ,设置不同 算法 取值不同

public   Transform PosList;
        public GameObject Item;// 
void Start()
        {
         StartCoroutine( CreateTest());
        }


 List vectorY = new List();
        List vectorX = new List();
        List vector2s = new List();
        Vector2 pos = new Vector2();
        float _mapWidth;
        float _mapHight;
        public  IEnumerator CreateTest()
        {
            _mapWidth = PosList.GetComponent().rect.width;//获取ui的实际宽度
            _mapHight = PosList.GetComponent().rect.height;//长度
            Vector2 pos2D = PosList.position;
            Debug.Log("_mapWidth=" + _mapWidth + "_mapHight=" + _mapHight + "  pos2Dx=" + pos2D.x + "  pos2Dy=" + pos2D.y);
            Debug.Log("Item.transform.GetComponent().rect.width=" + Item.transform.GetComponent().rect.width );
            float ItmeWidth = Item.transform.GetComponent().rect.width/2;
            float ItmeHeigh = Item.transform.GetComponent().rect.height/2;
            for (int i = 0; i             
关注
打赏
1663746399
查看更多评论
0.1936s