Unity3d the screen effect, bind this script to the main camera and call Shakecamera (); The code is as follows |
using unityengine;using system.collections;public class sc_shakecamera : monobehaviour { private float shaketime = 0.0f;private float fps= 20.0f;private float frameTime =0.0f;private float shakeDelta =0.005f; public camera cam ;p Ublic static bool isshakecamera =false;// use this for initializationvoid Start () {shaketime = 1.0f;fps= 20.0f; frametime =0.03f;shakedelta =0.005f; } // update is called once per framevoid update () {if (Isshakecamera) {if (shaketime > 0) {shakeTime - = time.deltatime;if (shaketime <= 0) {cam.rect = new rect (0.0f,0.0f,1.0f,1.0f); isshakecamera =false;shaketime = 1.0f;fps= 20.0f;frametime =0.03f;shakedelta = 0.005f;} Else{frametime += timE.deltatime; if (frametime > 1.0 / fps) {frametime = 0;cam.rect = new rect (shakedelta * ( -1.0f + 2.0f * random.value), ShakeDelta * ( -1.0f + 2.0f * random.value), 1.0f, 1.0f); }}}} } public static void shakecamera () {isshakecamera =true;}} You can also refer to http://blog.csdn.net/dujimache123/article/details/8149850
Unity3d Shock Screen effect