职位不重叠

时间:2019-02-04 13:05:21

标签: c# unity3d

我有一个创建对象并将其显示在场景上的方法。唯一的问题是,我发送给创建的对象的点有时会重叠,因此这些对象也会重叠。

private IEnumerator doBallSpawn()
{
    while (currentBallsCount < maxBallsIndex)
    {
        Vector3 pos = new Vector3(UnityEngine.Random.Range(MinX, MaxX), -8f, 0f);

        ObjectSequence ball = Instantiate(BallSequence, pos, Quaternion.identity) as ObjectSequence;
        ball.setCurrentChildIndex(BallColorRandom.getRandom());

        Vector3 goPosition = new Vector3(UnityEngine.Random.Range(MinX, MaxX), UnityEngine.Random.Range(MinY, MaxY));
        ball.transform.DOMove(goPosition, moveDuration);
        currentBallsCount++;
        ball.gameObject.GetOrAddComponent<SequenceMouseEvent>().MouseEvent += BallClickEvent;

        yield return new WaitForSeconds(delay);
    }
}

goPosition是我唯一需要更改的东西,但我不知道如何更改。

1 个答案:

答案 0 :(得分:0)

如果您的对象有碰撞器,则可以使用Bounds.Intersect方法来确定它们是否重叠。