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

这将在相同位置实例化预制件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);

        }


    

慕娘9325324
浏览 130回答 1
1回答

慕斯709654

尝试&nbsp;prefab.transform.position = rotateAroundTarget.transform.position + v + new Vector3(i, 0, 0);
打开App,查看更多内容
随时随地看视频慕课网APP