Unity - 如何在精灵到达屏幕边缘时旋转精灵?

时间:2014-05-21 01:20:55

标签: unity3d unityscript

我想旋转我的精灵,当它撞到屏幕的边缘时左右移动(所以它面向它移动的方向)

到目前为止我得到了这个:

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;    
} 

我怎样才能让它发挥作用?

1 个答案:

答案 0 :(得分:0)

使用transform.LookAtVector3.Slerp

transform.LookAt(Vector3.Slerp(Vector3.left,Vecto3.right, Mathf.PingPoing(pos, 10.0)));