?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);
}
效果
?
|