Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9513

BPMに合わせて光るライト

$
0
0
任意のBPMに合わせてLightを発光させるスクリプトです。 光らせたいLightオブジェクトに直接アタッチして使ってください。 「Decay」は光の減衰スピードです。 1より大きい値にすれば徐々に強くなる光にできます。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class BPMLight : MonoBehaviour { private Light light; private float currentTime; private float span; public int bpm = 120; //任意のBPM public float maxIntensity; //発光時の光の強さ public float minIntensity; //どこまで光が弱くなるか public float decay = 0.9f; //減衰率 void Start() { span = 60.0f / bpm; light = GetComponent<Light>(); light.intensity = maxIntensity; } void Update() { currentTime += Time.deltaTime; if(currentTime>span) { light.intensity = maxIntensity; currentTime = 0f; } light.intensity *= decay; } }

Viewing all articles
Browse latest Browse all 9513

Trending Articles