Vector3
- Vector3.up:即 Vector3(0, 1, 0)
- Vector3.down:即 Vector3(0, -1, 0)
- Vector3.forward:即 Vector3(0, 0, 1)
- Vector3.back:即 Vector3(0, 0, -1)
- Vector3.right:即 Vector3(1,0, 0)
- Vector3.left:即 Vector3(-1, 0, 0)
在 Scene 中画线(脚本挂给Cube)
void FixedUpdate()
{
Debug.DrawRay(transform.position, Vector3.up * 10, Color.black);//黑色
Debug.DrawRay(transform.position, Vector3.down * 10, Color.blue);//蓝色
Debug.DrawRay(transform.position, Vector3.forward * 10, Color.cyan);//青色
Debug.DrawRay(transform.position, Vector3.back * 10, Color.yellow);//黄色
Debug.DrawRay(transform.position, Vector3.left * 10, Color.magenta);//洋红
Debug.DrawRay(transform.position, Vector3.right * 10, Color.green);//绿色
}
结果
Transform
- transform.up:即 Vector3.up
- transform.forward:即 Vector3.forward
- transform.right:即 Vector3.right
tranform 是基于自身坐标系,而 Vector3 是基于世界坐标系。
void FixedUpdate()
{
Debug.DrawRay(transform.position, transform.up * 10, Color.yellow); //黄色
Debug.DrawRay(transform.position, transform.forward * 10, Color.cyan); //青色
Debug.DrawRay(transform.position, transform.right * 10, Color.green); //绿色
Debug.DrawRay(transform.position, Vector3.up * 10, Color.magenta);
Debug.DrawRay(transform.position, Vector3.down * 10, Color.magenta);
Debug.DrawRay(transform.position, Vector3.forward * 10, Color.magenta);
Debug.DrawRay(transform.position, Vector3.back * 10, Color.magenta);
Debug.DrawRay(transform.position, Vector3.left * 10, Color.magenta);
Debug.DrawRay(transform.position, Vector3.right * 10, Color.magenta);
}
效果
文章来源:https://www.toymoban.com/news/detail-413088.html
文章来源地址https://www.toymoban.com/news/detail-413088.html
到了这里,关于unity_Vector3.up 和 transform.up 的区别的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!