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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值