摄像机抖动

梦想游戏人
目录:
Unity

项目需要,所以写了个简易的

  IEnumerator shakeCamera()
    {

        Vector3 pos_orign = GetComponentInChildren<Camera>().GetComponent<Transform>().position;

        for (int i = 0; i < 20; i++)
        {
            yield return new WaitForSeconds(0.01f);
            Vector3 pos = GetComponentInChildren<Camera>().GetComponent<Transform>().position;

            pos.x = pos_orign.x+ Random.Range(-1.0f, 1.0f);
            pos.y = pos_orign.y+ Random.Range(-0.1f, 0.1f);
         //   pos.z += Random.Range(-10, 10);

            GetComponentInChildren<Camera>().GetComponent<Transform>().position=pos;

        }
        GetComponentInChildren<Camera>().GetComponent<Transform>().position = pos_orign;

    }
Scroll Up