C# Unity 3d围棋方向
我寻找最好的方法来检测GO(立方体)的哪个位置朝上。 我的研究使我找到了Dot产品。 我知道我想做什么,但我想我的c#技能太差了 基本上我只想找到点积,比如x旋转。C# Unity 3d围棋方向,c#,dot,dot-product,C#,Dot,Dot Product,我寻找最好的方法来检测GO(立方体)的哪个位置朝上。 我的研究使我找到了Dot产品。 我知道我想做什么,但我想我的c#技能太差了 基本上我只想找到点积,比如x旋转。 如果其值介于0,9到1之间,则一个位置朝上,对于-0,9到-1,另一个位置朝上,依此类推所有轴。在Unity的文档中,您有以下内容。你只需要稍微调整一下就可以达到你所需要的 // detects if other transform is behind this object using UnityEngine; using Sy
如果其值介于0,9到1之间,则一个位置朝上,对于-0,9到-1,另一个位置朝上,依此类推所有轴。在Unity的文档中,您有以下内容。你只需要稍微调整一下就可以达到你所需要的
// detects if other transform is behind this object
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
public Transform other;
void Update()
{
if (other)
{
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 toOther = other.position - transform.position;
if (Vector3.Dot(forward, toOther) < 0)
{
print("The other transform is behind me!");
}
}
}
}
//检测此对象后面是否有其他变换
使用UnityEngine;
使用系统集合;
公共类示例类:单一行为
{
公共关系和其他关系;
无效更新()
{
如果(其他)
{
Vector3 forward=transform.TransformDirection(Vector3.forward);
Vector3 toOther=其他.position-变换.position;
if(矢量3.点(向前,有齿)<0)
{
打印(“另一个变换在我后面!”);
}
}
}
}
谢谢,但我已经找到了,我无法将其调整为旋转而不是位置。我尝试了vector3和eulerAngles,但我无法让它工作。我知道这不是一个正确的问题,但我不知道如何调整旋转的代码。您是否尝试过transform.up
、transform.front
或transform.right
等?您必须在附加到对象的c#脚本中触发它们