1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

BPMに合わせて光るライト

Last updated at Posted at 2021-12-29

任意の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;
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?