
前回、前々回から作っていました簡単なスロットマシーンが完成しました!!
上のボタンから遊んでくださいね。
この記事では、スロットマシーンの遊び方やソースファイルの公開をします。
どのように作っているか気になる方は下記の記事も併せてどうぞ!
目次
スロットマシーンの遊び方
レバーをクリックして、リールを回し、ボタンを押して止めて下さい。
絵柄が揃うとメダルがもらえます。
リプレイを揃えるともう一回できます。
Brilliantを3つ揃えるとボーナスステージが始まります。
音楽が流れている間にリールを回すと7が沢山流れてきます!
絵柄製作者様・音源制作者様
以下の画像/音素材を使用させていただきました。
大変ありがとうございました。
今後ともどうぞよろしくお願いいたします。
絵柄のデザイン:赤7・青7・Brilliant・ベル・スイカ・チェリー・リプレイ:Mamag3(マメージ〉様
赤7の音:nakano sound様:ファンファーレ7(オープニング)
青7の音:nakano sound様:ファンファーレ5
Brilliantの音:MusMus様:tw046
その他の絵柄の音:nakano sound様:ファンファーレ6(戦闘勝利)
払い戻しベル音:soundbible.com様:Triangle Dinner Bell Sound: Recorded by CowBoyTyrone
ボタンの音:MusMus様:btn05
リールの回転音:MusMus様:btn10
レバーの音:soundbible.com様:Light Pull Chain Sound:Recorded by Daniel Simion
C#スクリプトのソースコード
GameController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameController : MonoBehaviour
{
AudioSource[] sounds;//オーディオの宣言
LeftTopGetter leftTopGetter;
LeftMiddleGetter leftMiddleGetter;
LeftBottomGetter leftBottomGetter;
CenterTopGetter centerTopGetter;
CenterMiddleGetter centerMiddleGetter;
CenterBottomGetter centerBottomGetter;
RightTopGetter rightTopGetter;
RightMiddleGetter rightMiddleGetter;
RightBottomGetter rightBottomGetter;
ReelGenerator1 reelGenerator1;
ReelGenerator1 reelGenerator2;
ReelGenerator1 reelGenerator3;
public GameObject medal;//メダルの宣言
public double coin;
int koyaku;
public GameObject score_object; // Textオブジェクト
public GameObject win_object; // Textオブジェクト
private void Awake()
{
sounds = gameObject.GetComponents<AudioSource>();//オーディオの取得
reelGenerator1 = GameObject.Find("ReelGenerator").GetComponent<ReelGenerator1>();
reelGenerator2 = GameObject.Find("ReelGenerator (1)").GetComponent<ReelGenerator1>();
reelGenerator3 = GameObject.Find("ReelGenerator (2)").GetComponent<ReelGenerator1>();
}
// Update is called once per frame
void Update()
{
Text score_text = score_object.GetComponent<Text>();
score_text.text = "$"+ coin.ToString("F2");
}
// Start is called before the first frame update
public void CheckMiddle()
{
Debug.Log("yobaretayo");
leftTopGetter = GameObject.Find("LeftTopGetter(Clone)").GetComponent<LeftTopGetter>();//LeftTopGetterの取得
leftMiddleGetter = GameObject.Find("LeftMiddleGetter(Clone)").GetComponent<LeftMiddleGetter>();//LeftMiddleGetterの取得
leftBottomGetter = GameObject.Find("LeftBottomGetter(Clone)").GetComponent<LeftBottomGetter>();//LeftBottomGetterの取得
centerTopGetter = GameObject.Find("CenterTopGetter(Clone)").GetComponent<CenterTopGetter>();//CenterTopGetterの取得
centerMiddleGetter = GameObject.Find("CenterMiddleGetter(Clone)").GetComponent<CenterMiddleGetter>();//CenterMiddleGetterの取得
centerBottomGetter = GameObject.Find("CenterBottomGetter(Clone)").GetComponent<CenterBottomGetter>();//CenterBottomGetterの取得
rightTopGetter = GameObject.Find("RightTopGetter(Clone)").GetComponent<RightTopGetter>();//RightTopGetterの取得
rightMiddleGetter = GameObject.Find("RightMiddleGetter(Clone)").GetComponent<RightMiddleGetter>();//RightMiddleGetterの取得
rightBottomGetter = GameObject.Find("RightBottomGetter(Clone)").GetComponent<RightBottomGetter>();//RightBottomGetterの取得
if (leftTopGetter.leftTopSymbol == centerTopGetter.centerTopSymbol && centerTopGetter.centerTopSymbol == rightTopGetter.rightTopSymbol)//上段の場合
{
koyaku = leftTopGetter.leftTopSymbol;
if (koyaku == 0)
{
sounds[0].Play();
StartCoroutine(Sound7Coroutine());
WinR7();
}
else if (koyaku == 1)
{
sounds[1].Play();
StartCoroutine(Sound7Coroutine());
Win7();
}
else if (koyaku == 2)
{
sounds[2].Play();
WinBrilliant();
}
else if (koyaku == 3)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinBell();
}
else if (koyaku == 4)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinCherry();
}
else if (koyaku == 5)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinWatermelon();
}
else
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinReplay();
}
}
if (leftMiddleGetter.leftMiddleSymbol == centerMiddleGetter.centerMiddleSymbol && centerMiddleGetter.centerMiddleSymbol == rightMiddleGetter.rightMiddleSymbol)//中段の場合
{
koyaku = leftMiddleGetter.leftMiddleSymbol;
if (koyaku == 0)
{
sounds[0].Play();
StartCoroutine(Sound7Coroutine());
WinR7();
}
else if (koyaku == 1)
{
sounds[1].Play();
StartCoroutine(Sound7Coroutine());
Win7();
}
else if (koyaku == 2)
{
sounds[2].Play();
WinBrilliant();
}
else if (koyaku == 3)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinBell();
}
else if (koyaku == 4)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinCherry();
}
else if (koyaku == 5)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinWatermelon();
}
else
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinReplay();
}
}
if (leftBottomGetter.leftBottomSymbol == centerBottomGetter.centerBottomSymbol && centerBottomGetter.centerBottomSymbol == rightBottomGetter.rightBottomSymbol)//下段の場合
{
koyaku = leftBottomGetter.leftBottomSymbol;
if (koyaku == 0)
{
sounds[0].Play();
StartCoroutine(Sound7Coroutine());
WinR7();
}
else if (koyaku == 1)
{
sounds[1].Play();
StartCoroutine(Sound7Coroutine());
Win7();
}
else if (koyaku == 2)
{
sounds[2].Play();
WinBrilliant();
}
else if (koyaku == 3)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinBell();
}
else if (koyaku == 4)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinCherry();
}
else if (koyaku == 5)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinWatermelon();
}
else
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinReplay();
}
}
if (leftTopGetter.leftTopSymbol == centerMiddleGetter.centerMiddleSymbol && centerMiddleGetter.centerMiddleSymbol == rightBottomGetter.rightBottomSymbol)//斜め右下の場合
{
koyaku = leftTopGetter.leftTopSymbol;
if (koyaku == 0)
{
sounds[0].Play();
StartCoroutine(Sound7Coroutine());
WinR7();
}
else if (koyaku == 1)
{
sounds[1].Play();
StartCoroutine(Sound7Coroutine());
Win7();
}
else if (koyaku == 2)
{
sounds[2].Play();
WinBrilliant();
}
else if (koyaku == 3)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinBell();
}
else if (koyaku == 4)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinCherry();
}
else if (koyaku == 5)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinWatermelon();
}
else
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinReplay();
}
}
if (leftBottomGetter.leftBottomSymbol == centerMiddleGetter.centerMiddleSymbol && centerMiddleGetter.centerMiddleSymbol == rightTopGetter.rightTopSymbol)//斜め右上の場合
{
koyaku = leftBottomGetter.leftBottomSymbol;
if (koyaku == 0)
{
sounds[0].Play();
StartCoroutine(Sound7Coroutine());
WinR7();
}
else if (koyaku == 1)
{
sounds[1].Play();
StartCoroutine(Sound7Coroutine());
Win7();
}
else if (koyaku == 2)
{
sounds[2].Play();
WinBrilliant();
}
else if (koyaku == 3)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinBell();
}
else if (koyaku == 4)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinCherry();
}
else if (koyaku == 5)
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinWatermelon();
}
else
{
sounds[3].Play();
StartCoroutine(SoundCoroutine());
WinReplay();
}
}
IEnumerator SoundCoroutine()//コルーチン本体
{
yield return new WaitForSeconds(1.5f);
sounds[4].Play();
}
IEnumerator Sound7Coroutine()//コルーチン本体
{
yield return new WaitForSeconds(5f);
sounds[5].Play();
}
}
void WinR7()
{
double win0 = 150.00f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = "$" + win0.ToString("F2") + "WIN!!";
for(int i = 0; i < 300; i++)
{
float randx = Random.Range(-7.5f, 7.5f);
float randy = Random.Range(5, 0.5f*300);
Instantiate(medal, new Vector3(randx, randy, 0.0f), Quaternion.identity);
}
}
void Win7()
{
double win1 = 100.00f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = "$" + win1.ToString("F2") + "WIN!!";
for (int i = 0; i < 200; i++)
{
float randx = Random.Range(-7.5f, 7.5f);
float randy = Random.Range(5, 0.5f * 200);
Instantiate(medal, new Vector3(randx, randy, 0.0f), Quaternion.identity);
}
}
void WinBrilliant()
{
Text win_text = win_object.GetComponent<Text>();
win_text.text = "BONUS STAGE!!! SPIN FAST!!!";
reelGenerator1.div0 = 30;//赤$$$が出るしきい値
reelGenerator1.div1 = 55;//$$$が出るしきい値
reelGenerator1.div2 = 60;//BARが出るしきい値
reelGenerator1.div3 = 75;//bが出るしきい値
reelGenerator1.div4 = 80;//%が出るしきい値
reelGenerator1.div5 = 85;//wが出るしきい値
//0が出るしきい値
reelGenerator2.div0 = 30;//赤$$$が出るしきい値
reelGenerator2.div1 = 55;//$$$が出るしきい値
reelGenerator2.div2 = 60;//BARが出るしきい値
reelGenerator2.div3 = 75;//bが出るしきい値
reelGenerator2.div4 = 80;//%が出るしきい値
reelGenerator2.div5 = 85;//wが出るしきい値
//0が出るしきい値
reelGenerator3.div0 = 30;//赤$$$が出るしきい値
reelGenerator3.div1 = 55;//$$$が出るしきい値
reelGenerator3.div2 = 60;//BARが出るしきい値
reelGenerator3.div3 = 75;//bが出るしきい値
reelGenerator3.div4 = 80;//%が出るしきい値
reelGenerator3.div5 = 85;//wが出るしきい値
//0が出るしきい値
StartCoroutine(BonusCoroutine());
}
IEnumerator BonusCoroutine()//コルーチン本体
{
yield return new WaitForSeconds(60f);
reelGenerator1.div0 = 7;//赤$$$が出るしきい値
reelGenerator1.div1 = 15;//$$$が出るしきい値
reelGenerator1.div2 = 20;//BARが出るしきい値
reelGenerator1.div3 = 40;//bが出るしきい値
reelGenerator1.div4 = 55;//%が出るしきい値
reelGenerator1.div5 = 80;//wが出るしきい値
//0が出るしきい値
reelGenerator2.div0 = 7;//赤$$$が出るしきい値
reelGenerator2.div1 = 15;//$$$が出るしきい値
reelGenerator2.div2 = 20;//BARが出るしきい値
reelGenerator2.div3 = 40;//bが出るしきい値
reelGenerator2.div4 = 55;//%が出るしきい値
reelGenerator2.div5 = 80;//wが出るしきい値
//0が出るしきい値
reelGenerator3.div0 = 7;//赤$$$が出るしきい値
reelGenerator3.div1 = 15;//$$$が出るしきい値
reelGenerator3.div2 = 20;//BARが出るしきい値
reelGenerator3.div3 = 40;//bが出るしきい値
reelGenerator3.div4 = 55;//%が出るしきい値
reelGenerator3.div5 = 80;//wが出るしきい値
//0が出るしきい値
}
void WinBell()
{
double win3 = 10.00f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = "$" + win3.ToString("F2") + "WIN!!";
for (int i = 0; i < 20; i++)
{
float randx = Random.Range(-7.5f, 7.5f);
float randy = Random.Range(5, 0.5f * 20);
Instantiate(medal, new Vector3(randx, randy, 0.0f), Quaternion.identity);
}
}
void WinCherry()
{
double win4 = 2.50f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = "$" + win4.ToString("F2") + "WIN!!";
for (int i = 0; i < 5; i++)
{
float randx = Random.Range(-7.5f, 7.5f);
float randy = Random.Range(5, 0.5f * 20);
Instantiate(medal, new Vector3(randx, randy, 0.0f), Quaternion.identity);
}
}
void WinWatermelon()
{
double win5 = 5.00f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = "$" + win5.ToString("F2") + "WIN!!";
for (int i = 0; i < 10; i++)
{
float randx = Random.Range(-7.5f, 7.5f);
float randy = Random.Range(5, 0.5f * 20);
Instantiate(medal, new Vector3(randx, randy, 0.0f), Quaternion.identity);
}
}
void WinReplay()
{
coin += 1.50f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = "Replay!!";
}
}
Reelcontroller.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Reelcontroller : MonoBehaviour
{
AudioSource[] sounds;//オーディオの宣言
public GameObject Reel; //リールを取得
public GameObject Reel2;
public GameObject Reel3;
Vector3 initialpos; //初期位置
Vector3 initialpos2;
Vector3 initialpos3;
public float speed1; //リールの回転速度
public float speed2;
public float speed3;
bool stopflag1 = false;//ボタンが押されたかどうか
bool stopflag2 = false;
bool stopflag3 = false;
bool allflag = true;
ReelGenerator1 reelGenerator1;//ReelGenerator1の宣言
ReelGenerator1 reelGenerator2;
ReelGenerator1 reelGenerator3;
GameController gameController;
private void Awake() //ゲーム開始時に
{
sounds = gameObject.GetComponents<AudioSource>();//オーディオの取得
initialpos = this.Reel.transform.position; //初期位置を取得しておく
initialpos2 = this.Reel2.transform.position;
initialpos3 = this.Reel3.transform.position;
reelGenerator1 = GameObject.Find("ReelGenerator").GetComponent<ReelGenerator1>();//ReelGenerator1の取得
reelGenerator2 = GameObject.Find("ReelGenerator (1)").GetComponent<ReelGenerator1>();
reelGenerator3 = GameObject.Find("ReelGenerator (2)").GetComponent<ReelGenerator1>();
gameController = GameObject.Find("GameController").GetComponent<GameController>();
}
public void StartReel()//リールを再生成して回し始める関数
{
DestroyGetter();
reelGenerator1.GenerateReel();//ReelGenerator1のGenerateReel関数を呼ぶ
reelGenerator2.GenerateReel();
reelGenerator3.GenerateReel();
speed1 = -0.35f; //リールの回転スピードの代入
speed2 = -0.35f;
speed3 = -0.35f;
stopflag1 = false; //ボタンを押していない状態にリセット
stopflag2 = false;
stopflag3 = false;
if (stopflag1 != true)
{
sounds[0].Play();//リール回転音プレイ
}
if (stopflag2 != true)
{
sounds[1].Play();//リール回転音プレイ
}
if (stopflag3 != true)
{
sounds[2].Play();//リール回転音プレイ
}
allflag = false;
}
private void Update() //ゲームが始まったら
{
this.Reel.transform.Translate(0, speed1, 0); //リールをy方向(下)に動かす
this.Reel2.transform.Translate(0, speed2, 0);
this.Reel3.transform.Translate(0, speed3, 0);
if (Reel.transform.position.y < -130) //リールが一番下に来たら
{
this.Reel.transform.position = initialpos; //初期位置に戻す
}
if (Reel2.transform.position.y < -130f)
{
this.Reel2.transform.position = initialpos2;
}
if (Reel3.transform.position.y < -130f)
{
this.Reel3.transform.position = initialpos3;
}
if (stopflag1 && 0.85 <= Mathf.Abs(Reel.transform.position.y % 1.5f) && Mathf.Abs(Reel.transform.position.y % 1.5f) < 0.88)
//ボタンが押されていて、かつ、リールを1.5fで割った余りが規定値以内であったら
{
speed1 = 0;//リールの回転スピードを0にする
}
if (stopflag2 && 0.85 <= Mathf.Abs(Reel2.transform.position.y % 1.5f) && Mathf.Abs(Reel2.transform.position.y % 1.5f) < 0.88)
{
speed2 = 0;
}
if (stopflag3 && 0.85 <= Mathf.Abs(Reel3.transform.position.y % 1.5f) && Mathf.Abs(Reel3.transform.position.y % 1.5f) < 0.88)
{
speed3 = 0;
}
if(speed1 == 0 && speed2 == 0 && speed3 == 0 && allflag != true)
{
allflag = true;
gameController.CheckMiddle();
}
}
public void stopReel() //この関数がボタン1を押すと呼ばれる
{
if (stopflag1 != true)//ボタンがまだ押されてない場合
{
speed1 = -0.03f;//リールをゆっくりにする
sounds[0].Stop();
}
stopflag1 = true; //ボタンを押す
}
public void stopReel2()
{
if (stopflag2 != true)
{
speed2 = -0.03f;
sounds[1].Stop();
}
stopflag2 = true;
}
public void stopReel3()
{
if (stopflag3 != true)
{
speed3 = -0.03f;
sounds[2].Stop();
}
stopflag3 = true;
}
public void DestroyGetter()
{ //絵柄ID取得プレファブをデストロイしてリセットする関数
GameObject[] getters = GameObject.FindGameObjectsWithTag("getter"); //getterタグが付いているオブジェクトをすべて取得
foreach (GameObject i in getters)//各getterのオブジェクトに対して以下を行う
{
Destroy(i);//getterの各オブジェクトを破壊する
}
}
}
ReelGenerator1.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReelGenerator1 : MonoBehaviour
{
public GameObject[] imgobj; //絵柄のプレハブを格納(計7種)
GameObject[] tmp_obj = new GameObject[90];//リールの配列(プレハブの種類が入る)
Transform[] img_pos = new Transform[90];//リールの柄の位置
Transform pos; //リールのTransform
public int div0 =7;//赤$$$が出るしきい値
public int div1 =15;//$$$が出るしきい値
public int div2 =39;//BARが出るしきい値
public int div3 =40;//bが出るしきい値
public int div4 =55;//%が出るしきい値
public int div5 =80;//wが出るしきい値
//0が出るしきい値
void Awake()//ゲーム開始時に
{
GenerateReel();//リール生成関数を呼び出す
}
public void GenerateReel()//リール生成関数本体
{
pos = GetComponent<Transform>();//リールのTransformはオブジェクト位置とする
for (int i = 0; i < 90; i++)
{
Vector3 pos = new Vector3(0.0f, -1.5f + (1.5f * i), 0.0f);//プレハブ位置の決定
int tmp;
int rand = Random.Range(0, 91);//0~91の数字をランダムで生成
if (0 < rand && rand < div0 //もし数字が0~赤$$$のしきい値以内だったら
)
{
tmp = 0;//赤$$$の絵柄idをtempに代入
}
else if (div0 < rand && rand < div1 // もし数字が赤$$$のしきい値~$$$のしきい値以内だったら
)
{
tmp = 1;//$$$の絵柄idをtempに代入
}
else if (div1 < rand && rand < div2 //以下他の絵柄について同様に
)
{
tmp = 2;
}
else if (div2 < rand && rand < div3
)
{
tmp = 3;
}
else if (div3 < rand && rand < div4
)
{
tmp = 4;
}
else if (div4 < rand && rand < div5
)
{
tmp = 5;
}
else
{
tmp = 6;
}
tmp_obj[i] = (GameObject)Instantiate(imgobj[tmp]); //プレハブからtempの絵柄idのGameObjectを生成
tmp_obj[i].transform.SetParent(transform, false); //リールのオブジェクトを親にする
img_pos[i] = tmp_obj[i].GetComponent<Transform>();//プレハブのtransformを取得
img_pos[i].localPosition = pos;//プレハブ位置の代入
}
}
public void DestroyReel() { //リールをデストロイしてリセットする関数
GameObject[] reels = GameObject.FindGameObjectsWithTag("reel"); //reelタグが付いているオブジェクトをすべて取得
foreach (GameObject i in reels)//各reelsのオブジェクトに対して以下を行う
{
Destroy(i);//reelsの各オブジェクトを破壊する
}
}
}
Lever.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Lever : MonoBehaviour
{
private AudioSource audioSource;//オーディオの宣言
public Reelcontroller reelcontroller;//ReelControllerの宣言
public ReelGenerator1 reelgenerator; //ReelGenerator1の宣言
public GameObject win_object; // Textオブジェクト
GameController gameController;
void Start()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//ReelControllerの取得
reelgenerator = GameObject.Find("ReelGenerator").GetComponent<ReelGenerator1>();//ReelGenerator1の取得
gameController = GameObject.Find("GameController").GetComponent<GameController>();//ReelGenerator1の取得
}
public void OnClick()
{
audioSource = gameObject.GetComponent<AudioSource>();//オーディオの取得
audioSource.Play();//ガチャっというオーディオの取得
this.transform.Translate(0, -4.33f, 0);//レバーを下に落とす
StartCoroutine(LeverCoroutine());//コルーチンを始める(レバーを0,5秒後に戻すため)
reelgenerator.DestroyReel();//リールを全消しする関数を呼ぶ
reelcontroller.StartReel();//リールを再生成して回す関数を呼ぶ
gameController.coin -= 1.50f;
Text win_text = win_object.GetComponent<Text>();
win_text.text = " ";
}
IEnumerator LeverCoroutine()//コルーチン本体
{
yield return new WaitForSeconds(0.5f);//0.5秒待つ
this.transform.Translate(0, 4.33f, 0);//レバーを元に戻す
}
}
XXXXXXX getter.csx9
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RightTopGetter : MonoBehaviour
{
public int rightTopSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
rightTopSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("rightTop" + rightTopSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RightMiddleGetter : MonoBehaviour
{
public int rightMiddleSymbol;
Reelcontroller reelcontroller;
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>();
//cardModel.ToggleFace(false);
rightMiddleSymbol = reelSymbol.symbolNum;
Debug.Log("rightMiddle" + rightMiddleSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RightBottomGetter : MonoBehaviour
{
public int rightBottomSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
rightBottomSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("rightBottom" + rightBottomSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CenterTopGetter : MonoBehaviour
{
public int centerTopSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
centerTopSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("centerTop" + centerTopSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CenterMiddleGetter : MonoBehaviour
{
public int centerMiddleSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
centerMiddleSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("centerMiddle" + centerMiddleSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CenterBottomGetter : MonoBehaviour
{
public int centerBottomSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
centerBottomSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("centerBottom" + centerBottomSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeftTopGetter : MonoBehaviour
{
public int leftTopSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
leftTopSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("leftTop" + leftTopSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeftMiddleGetter : MonoBehaviour
{
public int leftMiddleSymbol;
Reelcontroller reelcontroller;
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>();
leftMiddleSymbol = reelSymbol.symbolNum;
Debug.Log("LeftMiddle" + leftMiddleSymbol);
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeftBottomGetter : MonoBehaviour
{
public int leftBottomSymbol;
Reelcontroller reelcontroller;//Reelcontrollerの宣言
private void Awake()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("reel"))//reelタグが付いたオブジェクトにぶつかったら
{
ReelSymbol reelSymbol = other.GetComponent<ReelSymbol>(); //ぶつかった相手のReelSymbolにアクセス
leftBottomSymbol = reelSymbol.symbolNum; //symbolNumをcenterMiddleSymbolに代入する
Debug.Log("leftBottom" + leftBottomSymbol);
}
}
}
buttonX.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Button1 : MonoBehaviour
{
private AudioSource audioSource;//オーディオの宣言
public GameObject leftTopGetter;//leftMiddleGetterの宣言
public GameObject leftMiddleGetter;//leftMiddleGetterの宣言
public GameObject leftBottomGetter;//leftMiddleGetterの宣言
public Reelcontroller reelcontroller;
void Start()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();
}
public void OnClick()
{
reelcontroller.stopReel();
audioSource = gameObject.GetComponent<AudioSource>();//オーディオの取得
audioSource.Play();//ぴこっというオーディオの取得
Instantiate(leftTopGetter, new Vector3(2.97f, 2.57f, 0.0f), Quaternion.identity);
Instantiate(leftMiddleGetter, new Vector3(2.97f, 1.06f, 0.0f), Quaternion.identity);
Instantiate(leftBottomGetter, new Vector3(2.97f, -0.49f, 0.0f), Quaternion.identity);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class button2 : MonoBehaviour
{
private AudioSource audioSource;//オーディオの宣言
public Reelcontroller reelcontroller;
public GameObject centerTopGetter;//centerMiddleGetterの宣言
public GameObject centerMiddleGetter;//centerMiddleGetterの宣言
public GameObject centerBottomGetter;//centerMiddleGetterの宣言
// Start is called before the first frame update
void Start()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();
}
public void OnClick()
{
reelcontroller.stopReel2();
audioSource = gameObject.GetComponent<AudioSource>();//オーディオの取得
audioSource.Play();//ぴこっというオーディオの取得
Instantiate(centerTopGetter, new Vector3(5.98f, 2.57f, 0.0f), Quaternion.identity);//中リール上段にインスタンス化
Instantiate(centerMiddleGetter, new Vector3(5.98f, 1.06f, 0.0f), Quaternion.identity);//中リール中段にインスタンス化
Instantiate(centerBottomGetter, new Vector3(5.98f, -0.49f, 0.0f), Quaternion.identity);//中リール上段にインスタンス化
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class button3 : MonoBehaviour
{
private AudioSource audioSource;//オーディオの宣言
public Reelcontroller reelcontroller;
public GameObject rightTopGetter;
public GameObject rightMiddleGetter;
public GameObject rightBottomGetter;
// Start is called before the first frame update
void Start()
{
reelcontroller = GameObject.Find("ReelController").GetComponent<Reelcontroller>();
}
public void OnClick()
{
reelcontroller.stopReel3();
audioSource = gameObject.GetComponent<AudioSource>();//オーディオの取得
audioSource.Play();//ぴこっというオーディオの取得
Instantiate(rightTopGetter, new Vector3(8.94f, 2.57f, 0.0f), Quaternion.identity);
Instantiate(rightMiddleGetter, new Vector3(8.94f, 1.06f, 0.0f), Quaternion.identity);
Instantiate(rightBottomGetter, new Vector3(8.94f, -0.49f, 0.0f), Quaternion.identity);
}
// Update is called once per frame
void Update()
{
}
}
medalgetter.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MedalGetter : MonoBehaviour
{
GameController gameController;
private void Awake()
{
gameController = GameObject.Find("GameController").GetComponent<GameController>();//Reelcontrollerの取得
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("medal"))
{
Destroy(other.gameObject); //ぶつかった相手をディアクティベート(消える
gameController.coin += 0.5f;
}
}
}
ReelSymbol.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReelSymbol : MonoBehaviour
{
public int symbolNum;
}
まとめ
やっと完成まで漕ぎつけました!
久しぶりのUNITYだったので、最初は全然コードを書けなかったのですが、徐々に思い出してきました。
このモメンタムを失わないうちに何か新しいことに挑戦していきたいと思います。
コードは全文を張り付けてありますので、もしよかったらご参考になれば幸いです。
今後ともどうぞよろしくお願い申し上げます。
それではまた!











