Unity功能 屏幕震動、抖動效果

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// boss攻擊玩家產生的震動方法
/// 掛載到主攝像機上
/// </summary>
public class Shake : MonoBehaviour {


    private float cameraShake = 2;//震動係數
    public GameObject UI;//紅色的背景圖片

	
    void Update () {
        if (Gun.Instance.bossAttack)
        {

            UI.SetActive(true);
            //X,Y軸震動
            transform.position = new Vector3((Random.Range(0f, cameraShake)) - cameraShake*0.5f, transform.position.y, transform.position.z);
            //Z軸震動
            transform.position = new Vector3(transform.position.x, transform.position.y, (Random.Range(0f, cameraShake)) - cameraShake * 0.5f);
            cameraShake = cameraShake / 1.05f;
            if (cameraShake<0.05f)
            {

                cameraShake= 0;
                UI.SetActive(false);
                Gun.Instance.bossAttack = false;
            }
        }
        else
        {
            cameraShake = 5;
        }
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章