如何避免没有刚体的GameObject重叠? [英] How to avoid overlapping of GameObject without rigidbody?

查看:97
本文介绍了如何避免没有刚体的GameObject重叠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方法,以使我的游戏对象不与另一个游戏对象重叠,但是所有解决方案都在讨论刚体".

I was looking for a way to make my gameobject not overlap to the another gameobject but all the solutions are talking about Rigidbody..

当我只想在脚本中不使用刚体时可以吗?我有一个缩放比例为(3,1,1)的立方体,我让他绕自身旋转,但是由于他的x缩放比例为3,我遇到了重叠问题

when i want to do it in script only without rigidbody, is it possible ? I have a cube with this scale (3,1,1) I make him rotate around itself but i got the overlap problem because his x scale is 3

反正有没有让他自动移动并回避红色游戏物体的方法?

Is there anyway to make him move and back automatically to avoid the red gameobject?

图像

推荐答案

您可以使用此方法

GameObject myDraggedGO; // parent

     private IEnumerator OverLapChecker(float delay)
        {
            yield return new WaitForSeconds(delay);
            Collider2D[] colls = new Collider2D[3];
            List<int> nums = new List<int>();
            foreach (var tile in myDraggedGO.GetComponentsInChildren<Rigidbody2D>())
            {
                nums.Add(Physics2D.OverlapCircleNonAlloc(tile.transform.position, 0.5f, colls));
            }
            if (nums.Contains(2))
            {
                myDraggedGO.transform.position = _startpositionOnDrag;
            }
        }

这篇关于如何避免没有刚体的GameObject重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆