为了账号安全,请及时绑定邮箱和手机立即绑定

如何在每个实例化对象之间添加间隙?

如何在每个实例化对象之间添加间隙?

C#
慕娘9325324 2021-05-02 13:14:56
这将在相同位置实例化预制件10次。我想在对象之间添加相等的间隙。预制件应在绘制的圆上实例化。我想要里面:if (moveInCircles)要圈出所有新的预制件。using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class rotate : MonoBehaviour{    [Header("Spin")]    public bool spin = true;    public Vector3 Direction;    [Range(0, 300)]    public float speed = 10f;    public bool randomSpeed = false;    public bool randomDirection = false;    [Range(0f, 100f)]    public float timeDirChange;    public Vector3 defaultDirection = new Vector3(1, 0, 0);    [Space(5)]    [Header("Move in circles")]    public bool moveInCircles = false;    public GameObject rotateAroundTarget;    public Vector3 axis;//by which axis it will rotate. x,y or z.    public float rotationSpeed; //or the speed of rotation.    public float upperLimit, lowerLimit, delay;// upperLimit & lowerLimit: heighest & lowest height;    [Range(5, 50)]    public float radius = 5;    private float height, prevHeight, time;//height:height it is trying to reach(randomly generated); prevHeight:stores last value of height;delay in radomness;     private float nextRotationTime = 0f;    private int counter = 0;    public DrawCircle dc;    public GameObject prefab;    public int numOfObjects;    public int gap = 3;    // Use this for initialization    void Start()    {        dc.xradius = radius;        if (prefab != null)        {            for (int i = 0; i < numOfObjects; i++)            {                Instantiate(prefab);                var v = Quaternion.AngleAxis(Time.time * speed, Vector3.up) * new Vector3(radius, 0, 0);                //prefab.transform.position = rotateAroundTarget.transform.position + v;                prefab.transform.position = rotateAroundTarget.transform.position + v + new Vector3(rotateAroundTarget.transform.position.x * gap,0, 0);            }        }    }    private void Update()    {        if (randomSpeed)        {            speed = UnityEngine.Random.Range(0, 300);        }    
查看完整描述

1 回答

?
慕斯709654

TA贡献1840条经验 获得超5个赞

尝试 prefab.transform.position = rotateAroundTarget.transform.position + v + new Vector3(i, 0, 0);


查看完整回答
反对 回复 2021-05-16
  • 1 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信