注意到位置不重叠

问题描述 投票:0回答:1

我有一个创建对象,并显示在场景的方法。唯一的问题是,我发送到创建的对象的点有时会有所重叠,所以对象也重叠。

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是我必须要改变的唯一的事,但我不知道怎么办。

c# unity3d
1个回答
0
投票

如果你的对象有对撞机,你可以使用Bounds.Intersect方法知道他们是否重叠。

© www.soinside.com 2019 - 2024. All rights reserved.