【Unity】Unity3d摄影机晃动特效【C#脚本】

using UnityEngine;
using System.Collections;

public class CameraMove : MonoBehaviour
{

	float shake = 5;
  
	float setShake;
  
	bool shakeSwitch = false;

	void Start ()
	{
  
		setShake = shake;
  
	}

	void OnGUI ()
	{
  
		if (GUILayout.Button ("Shake")) {
  
			shake = setShake;
  
			shakeSwitch = true;
  
		}
  
	}

	void Update ()
	{
  
		if (shakeSwitch == true) {

			gameObject.transform.position = new Vector3(Random.Range (0f, shake * 2f) - shake,transform.position.y,transform.position.z);

			gameObject.transform.position = new Vector3(transform.position.x,Random.Range (0f, shake * 1f) - shake,transform.position.z);
  
			shake = shake / 1.05f;
  
			if (shake < 0.05) {
  
				shake = 0;
  
				shakeSwitch = false;
  
			}
  
		}
  
	}
}

你可能感兴趣的:(【Unity】,unity,效果)