LoginSignup
18
17

More than 5 years have passed since last update.

Simple Skyで素敵な空 一枚のテクスチャで一日の空の演出

Last updated at Posted at 2015-08-22

Simple Sky

こちらの無料のアセットが空の演出に使いやすかったので・・・。
131.png

パッケージをインポートしたところ

スクリーンショット 2015-08-22 13.16.58.png

モデルが複数ありますがテクスチャは1枚でこれをUVでスクロールさせることで一枚の画像で昼も夜も表現可能です。
シーンを見るとSkyDomeが空のprefabでその下に月や星、太陽があり、雲はCloudsの下にあるので
Activeを切り替えるだけでOK
スクリーンショット 2015-08-22 13.20.54.png

手動で動かしてみたところ

sky.gif

ソースをちょろっと書いてScriptで動くように

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

public class SkyManager : MonoBehaviour {

    public Transform skyTran;
    public Transform croudParentTran;
    public GameObject star;
    public GameObject sun;
    public GameObject moon;
    public Material skyMaterial;

    private List<Transform> croudList;
    private float timeSpeed = 5f;   // 5秒で一周するように
    private float skyRotateSpeed = 0;  
    private float cloudMoveSpeed = 1f;
    private float nowTime = 0;


    void Awake()
    {
        skyRotateSpeed = 360f/timeSpeed;
        croudList = new List<Transform>();
        foreach(Transform tran in croudParentTran)
        {
            croudList.Add (tran);
        }
    }

    void Update () {
        nowTime += Time.deltaTime;
        float nowValue = Mathf.Clamp(nowTime / timeSpeed, 0f, 1f);
        if(nowTime > timeSpeed) nowTime = 0;
        skyMaterial.SetTextureOffset("_MainTex", new Vector2( nowValue, 0 ));
        skyTran.Rotate (new Vector3(0, skyRotateSpeed * Time.deltaTime, 0));
        foreach(Transform tran in croudList)
        {
            tran.transform.position += new Vector3(cloudMoveSpeed * Time.deltaTime, 0, 0);
        }

        if(0.2 < nowValue && nowValue < 0.6f)
        {
            star.SetActive(true);
            moon.SetActive(true);
            sun.SetActive(false);
        }
        else
        {
            star.SetActive(false);
            moon.SetActive(false);
            sun.SetActive(true);
        }
    }
}

sky2.gif

うんいい感じ

画像一枚で昼よるってどんな感じのテクスチャ展開なんだろう・・・。

と思ったのでみてみました。


スクリーンショット 2015-08-22 13.49.48.png
全て真ん中によってる。なるほど。

こちら雲
雲は下の方に一直線
スクリーンショット 2015-08-22 13.53.49.png

太陽と月は上の方に
スクリーンショット 2015-08-22 13.53.13.png

こう作るのかと関心してしまった。覚えておこう。

18
17
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
18
17