三つのボタンをそれぞれクリックすると、白、赤、青、白…の順にボタンの色が変わって、三つのボタンの色が白、赤、青それぞれこの順番になったときに扉が開くというスクリプトを作りたい
c# コード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class color : MonoBehaviour {
public GameObject whitecube; public GameObject bluecube; public GameObject redcube; public const int white = 1; public const int red = 2; public const int blue = 3; private int colorno; // Use this for initialization void Start () { colorno = white; } // Update is called once per frame void Update () { } public void PushLamp1button() { colorno++;
if (colorno > white)
{
colorno = white; } colorchange(); }
void colorchange()
{
switch (colorno) { case white: whitecube.SetActive(true); bluecube.SetActive(false); redcube.SetActive(false); break; case blue: whitecube.SetActive(false); bluecube.SetActive(true); redcube.SetActive(false); break; case red: whitecube.SetActive(false); bluecube.SetActive(false); redcube.SetActive(true); break; } }
}
一つ目のボタンの処理をこのように書いて、三つともこのスクリプトをアタッチして動かそうとしたが、一つ目のボタンの色を変えようとしても変えられない。
ちなみにイベントトリガーをつかっています
配列を使ったほうが絶対簡単になるのでしょうけど、いくら勉強をしても配列が理解できないので、これで行こうと思いました。
コンパイルエラーはでませんでした。
このスクリプトはあっているのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/30 08:50