我想旋转我的精灵,当它撞到屏幕的边缘时左右移动(所以它面向它移动的方向)
到目前为止我得到了这个:
function Start () {
pos = Random.Range (-4.0, 10.0);
transform.position.x = pos - 4.0;
//transform.Rotate (Vector3.up * 180);
}
function Update () {
pos -= Time.deltaTime;
transform.position.x = Mathf.PingPong (pos, 10.0) - 6.0;
}
我怎样才能让它发挥作用?
答案 0 :(得分:0)
使用transform.LookAt和Vector3.Slerp:
transform.LookAt(Vector3.Slerp(Vector3.left,Vecto3.right, Mathf.PingPoing(pos, 10.0)));