unity围绕围绕一个点动态生成

	//初始调用
	 private void Start()
    {
        float anjle_0 = 0;//角度
         float dis = 25;//距离
        Vector3 point = t1.localPosition; //初始点向上加
        point.y += 5;
        for (int i = 0; i < 3; i++)
        {
            anjle_0 += 10; dis -= 10;
            CreateCubeAngle30(anjle_0, dis,point);
        }
    }
 	public Transform prefab;       //预设物
    private Vector3 centerPos;    //你围绕那个中心点
    private float angle = 0;      //偏移角度 
    void CreateCubeAngle30(float ang, float dic,Vector3 point)
    {
        centerPos = t1.localPosition;
        for (angle = 0; angle < 360; angle += ang)
        {
            float x = centerPos.x + dic * Mathf.Cos(angle * 3.14f / 180f);
            float y = centerPos.y + dic * Mathf.Sin(angle * 3.14f / 180f);
            var floor = Instantiate(prefab);
            //floor.SetParent(meteorite_ball.parent, true);
            floor.localPosition = new Vector3(x, centerPos.z, y);
            float ran = UnityEngine.Random.Range(2f, 4f);
            floor.localScale = new Vector3(2, 15, 2);
            floor.LookAt(point);
        }
    }

//运行输出效果图
在这里插入图片描述
参考链接:https://blog.csdn.net/a770kfof/article/details/52808442

猜你喜欢

转载自blog.csdn.net/weixin_44431724/article/details/105664414
今日推荐