我使用下面的代码围绕我的游戏对象绘制一个圆圈:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(LineRenderer))]
public class DrawCircle : MonoBehaviour
{
[Range(0, 50)]
public int segments = 50;
[Range(0, 5)]
public float xradius = 5;
[Range(0, 5)]
public float yradius = 5;
LineRenderer line;
void Start()
{
line = gameObject.GetComponent<LineRenderer>();
line.positionCount = segments + 1;
line.useWorldSpace = false;
CreatePoints();
}
void Update()
{
CreatePoints();
}
void CreatePoints()
{
float x;
float y;
float z;
float angle = 20f;
for (int i = 0; i < (segments + 1); i++)
{
x = Mathf.Sin(Mathf.Deg2Rad * angle) * xradius;
z = Mathf.Cos(Mathf.Deg2Rad * angle) * yradius;
line.SetPosition(i, new Vector3(x, 0, z));
angle += (360f / segments + 1);
}
}
}
假设如果我将这个 Circle 类添加为对象 A 和对象 B 的组件。我将如何确定对象 A 上的圆是否与对象 B 上的圆接触?
最佳答案
如果圆心之间的距离大于其半径之和,则圆不接触。如果它更小,他们会做
关于c# - 如何确定两个圆圈是否重叠或接触?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54390129/