LoginSignup
0
0

More than 1 year has passed since last update.

スモールライトを作る

Last updated at Posted at 2021-06-19

スモールライトを用意する

small_light.png
まずスモールライトをモデリングします。
こちらの動画を参考に作成しました。

【blender初心者】ドラえもん・スモールライトを超簡単モデリング!
https://www.youtube.com/watch?v=VlsbqZXfC-U






small_light_2.png
光のシェイプも仕込んでおきます。





SmallLight_Trigger.PNG
球のコライダーを2つTrigger状態でつけます。
RigidBodyも取り付けてください。





縮めたいオブジェクトに取り付けるスクリプト

Smallable.cs
using UnityEngine;

public class Smallable : MonoBehaviour
{
    // 最小サイズ
    public Vector3 MinScale = Vector3.one;
    // 縮んでいく比率
    public Vector3 ScaleRate = Vector3.one * 0.001f;
}

Cubeなどに取り付けてください。





縮めるスクリプト

SmallLightScaler.cs
using UnityEngine;

public class SmallLightScaler : MonoBehaviour
{
    void OnTriggerStay(Collider other)
    {
        var smallable = other.gameObject.GetComponent<Smallable>();
        if(smallable == null)
        {
            return;
        }

        var scale = smallable.transform.localScale;
        if(scale == smallable.MinScale)
        {
            return;
        }

        scale.x = Mathf.Max(smallable.MinScale.x, scale.x - smallable.ScaleRate.x);
        scale.y = Mathf.Max(smallable.MinScale.y, scale.y - smallable.ScaleRate.y);
        scale.z = Mathf.Max(smallable.MinScale.z, scale.z - smallable.ScaleRate.z);

        smallable.transform.localScale = scale;
    }
}

このスクリプトをスモールライトに取り付けます。
Smallableを取り付けたオブジェクトに当たっている場合、縮まります。





結果

Small_Light_Result.gif





おわり

応用でビッグライトも作れます。

0
0
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
0
0