以下の方法で設定したcubeの色を変えています。
目覚まし時計の設定をしており、複数の時間を設定したいですが、どのようにif文を組み合わせるべきでしょうか
using UnityEngine; using System.Collections; public class Mycube : MonoBehaviour { public GameObject Mycube; // Use this for initialization void Start() { //gameObject取得 Mycube = GameObject.Find("cube"); } // Update is called once per frame void Update () { DateTime now = DateTime.Now; //スヌーズ指定 TimeSpan snuze = new TimeSpan( 0,20, 0); //start TimeSpan start = new TimeSpan(10, 50, 0); TimeSpan end = start + snuze; TimeSpan timeofday = now.TimeOfDay; if (timeofday.CompareTo(start) >= 0 && timeofday.CompareTo(end) < 0) {Mycube.GetComponent<Renderer>().material.color = Color.yellow;} else {Mycube.GetComponent<Renderer>().material.color = Color.back;} } }
回答1件
あなたの回答
tips
プレビュー