1
2

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に合わせてオブジェクトを点滅させる(HDRP/lit編)

Posted at

#HDRPでオブジェクトを点滅させたい

させたいですよね。

最初はHDRP/litの_EmissiveIntensityをスクリプトから操作して点滅させようとしましたが、値は変わるのにGameViewに反映されませんでした。
あきらめて、_BaseColorで点滅させられるように作りました。
EmissiveColorを前もって明度の高い色(白)にしておけば、
ぴかぴか点滅してくれます。

色はスクリプト上でいじります。
インスペクタ―で設定できるのはBPMだけです。

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

public class EmissionBlinking : MonoBehaviour
{


    private Material material;
    private float length = 1.0f;

    public int bpm = 120;
    

    void Start()
    {
        material = GetComponent<Renderer>().material;
    }

    void Update()
    {
        float span = bpm / 60; //1秒に何ビートか?
        float val = Mathf.PingPong(Time.time * span * 2f, length); //BPMの拍に合わせて点灯させるために *2 する

        Color color = new Color(1.0f - val * val, 0f, 0f); //RGBで任意の色にする

        material.SetColor("_BaseColor", color);
    }

}

プログラミングなんてできねえ!
と思いながら始めたC#学習も、なんとかかんとか触りだけはこなせました。

よい映像制作につながるように来年もがんばります。

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?