ふぃるゲ〜

ゲームアプリの開発をしています。また、作曲もしています。

【お肉ぱくぱくデブエット】操作方法

f:id:filltomkun:20210519224025p:plain

1・・・プレイヤー

ひたすら食べます。

食べれば食べるだけ太ります。

 

2・・・照準

この位置に来たコマンドを入力することでプレイヤーが肉を食べます。

 

3・・・コマンド

肉を1つ食べるごとに左にずれていきます。

コマンドの順を覚えておきましょう。

 

4・・・スコア

現在食べている肉の数が表示されます。

 

5・・・タイム

ゲームの残り時間が表示されます。

制限時間は30秒なので、ひたすら食べることに集中しましょう。

 

「お肉ぱくぱくデブエット!」をApp Storeで

 

スクリプト

 

・ゲームマネージャー

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

public class GameManager : MonoBehaviour
{
    float delta = 30;
    float end = 0;
    GameObject SecondsText;
    public GameObject End;

    void Start()
    {
        SecondsText = GameObject.Find("Seconds");
    }

    // Update is called once per frame
    void Update()
    {
        delta -= Time.deltaTime;
        SecondsText.GetComponent<Text>().text = delta.ToString("F1");

        if (delta <= end)
        {
            End.SetActive(true);
        }
    }
}

 

・ゲーム開始処理

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

public class GameStart : MonoBehaviour
{
    GameObject mv;
    GameObject gm;
    GameObject gari;
    GameObject mg;
    float delta = 0;
    float span = 1.4f;

    void Start()
    {
        mv = GameObject.Find("Move");
        gm = GameObject.Find("GameManager");
        gari = GameObject.Find("gari");
        mg = GameObject.Find("MeatGenerator");
    }

    void Update()
    {

        delta += Time.deltaTime;

        if (delta > span)
        {
            mv.GetComponent<Move>().enabled = true;
            mv.GetComponent<AudioSource>().enabled = true;
            gm.GetComponent<GameManager>().enabled = true;
            gari.GetComponent<PlayerController>().enabled = true;
            mg.GetComponent<MeatGenerator>().enabled = true;
            Destroy(gameObject);
        }
    }
}

 

・ゲーム終了処理

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

public class GameEnd : MonoBehaviour
{
    GameObject mv;
    GameObject gm;
    GameObject gari;
    GameObject mg;
    float delta = 0;
    int span = 2;

    void Start()
    {
        mv = GameObject.Find("Move");
        gm = GameObject.Find("GameManager");
        gari = GameObject.Find("gari");
        mg = GameObject.Find("MeatGenerator");
    }

    void Update()
    {

        delta += Time.deltaTime;
        mv.GetComponent<Move>().enabled = false;
        gm.GetComponent<GameManager>().enabled = false;
        mv.GetComponent<AudioSource>().enabled = false;
        gari.GetComponent<PlayerController>().enabled = false;
        mg.GetComponent<MeatGenerator>().enabled = false;

        if (delta > span)
        {
            SceneManager.LoadScene("Result");
        }
    }
}

 

・プレイヤー太る処理

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

public class PlayerController : MonoBehaviour
{

    Animator animator;
    GameObject mv;
    GameObject re;

    void Start()
    {
        animator = GetComponent<Animator>();
        mv = GameObject.Find("Move");
        re = GameObject.Find("Reset");
    }

    void Update()
    {
        if (mv.GetComponent<Move>().EatSwitch == true)
        {
            animator.SetTrigger("EatTrigger");
            mv.GetComponent<Move>().EatSwitch = false;
            GetComponent<AudioSource>().Play();
        }

        if (re.GetComponent<ScoreReset>().NomalSwitch == true)
        {
            animator.SetTrigger("NomalTrigger");
        }

        if (re.GetComponent<ScoreReset>().FatSwitch == true)
        {
            animator.SetTrigger("FatTrigger");
        }

    }
}

 

・コマンド処理

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

public class A : MonoBehaviour
{
    GameObject gd;
    GameObject mv;

    void Start()
    {
        gd = GameObject.Find("GameDirector");
        mv = GameObject.Find("Move");
    }

    void Update()
    {
        if (transform.position.x <= -4.5f)
        {
            Destroy(gameObject);
            gd.GetComponent<GameDirector>().AddPoint();
        }
    }

    void OnTriggerEnter2D(Collider2D Other)
    {
        mv.GetComponent<Move>().ConnectA = true;
    }

    void OnTriggerExit2D(Collider2D Other)
    {
        mv.GetComponent<Move>().ConnectA = false;
    }
}

 

・コマンド移動

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

public class Move: MonoBehaviour
{
    GameObject sw;
    GameObject ag;
    public bool ConnectA;
    public bool ConnectB;
    public bool ConnectU;
    public bool ConnectR;
    public bool ConnectD;
    public bool ConnectL;
    bool AbuttonSwitch;
    bool BbuttonSwitch;
    bool UbuttonSwitch;
    bool RbuttonSwitch;
    bool DbuttonSwitch;
    bool LbuttonSwitch;
    public bool EatSwitch = false;
    public bool MeatSwitch = false;

    void Start()
    {
        sw = GameObject.Find("Switch");
        ag = GameObject.Find("ArrowGenerator");
    }

    void Update()
    {
        if (ConnectA == true)
        {
            if (AbuttonSwitch == true)
            {
                ag.GetComponent<ArrowGenerator>().Switch = true;
                transform.Translate(-1, 0, 0);
                EatSwitch = true;
                MeatSwitch = true;
            }
        }

        if (ConnectB == true)
        {
            if (BbuttonSwitch == true)
            {
                ag.GetComponent<ArrowGenerator>().Switch = true;
                transform.Translate(-1, 0, 0);
                EatSwitch = true;
                MeatSwitch = true;
            }
        }

        if (ConnectU == true)
        {
            if (UbuttonSwitch == true)
            {
                ag.GetComponent<ArrowGenerator>().Switch = true;
                transform.Translate(-1, 0, 0);
                EatSwitch = true;
                MeatSwitch = true;
            }
        }

        if (ConnectR == true)
        {
            if (RbuttonSwitch == true)
            {
                ag.GetComponent<ArrowGenerator>().Switch = true;
                transform.Translate(-1, 0, 0);
                EatSwitch = true;
                MeatSwitch = true;
            }
        }

        if (ConnectD == true)
        {
            if (DbuttonSwitch == true)
            {
                ag.GetComponent<ArrowGenerator>().Switch = true;
                transform.Translate(-1, 0, 0);
                EatSwitch = true;
                MeatSwitch = true;
            }
        }

        if (ConnectL == true)
        {
            if (LbuttonSwitch == true)
            {
                ag.GetComponent<ArrowGenerator>().Switch = true;
                transform.Translate(-1, 0, 0);
                EatSwitch = true;
                MeatSwitch = true;
            }
        }

        if (AbuttonSwitch == true)
        {
            AbuttonSwitch = false;
        }

        if (BbuttonSwitch == true)
        {
            BbuttonSwitch = false;
        }

        if (UbuttonSwitch == true)
        {
            UbuttonSwitch = false;
        }

        if (RbuttonSwitch == true)
        {
            RbuttonSwitch = false;
        }

        if (DbuttonSwitch == true)
        {
            DbuttonSwitch = false;
        }

        if (LbuttonSwitch == true)
        {
            LbuttonSwitch = false;
        }
    }

    public void AbuttonDown()
    {
        AbuttonSwitch = true;
    }

    public void BbuttonDown()
    {
        BbuttonSwitch = true;
    }

    public void UbuttonDown()
    {
        UbuttonSwitch = true;
    }

    public void RbuttonDown()
    {
        RbuttonSwitch = true;
    }

    public void DbuttonDown()
    {
        DbuttonSwitch = true;
    }

    public void LbuttonDown()
    {
        LbuttonSwitch = true;
    }
}

 

・コマンドジェネレーター

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

public class ArrowGenerator : MonoBehaviour
{
    public GameObject Aprefab;
    public GameObject Bprefab;
    public GameObject Uprefab;
    public GameObject Rprefab;
    public GameObject Dprefab;
    public GameObject Lprefab;
    GameObject sw;
    GameObject mv;

    public bool Switch = true;

    void Start()
    {
        mv = GameObject.Find("Move");
        sw = GameObject.Find("Switch");
    }

    // Update is called once per frame
    void Update()
    {
        if (Switch == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.parent = mv.transform;
                Switch = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.parent = mv.transform;
                Switch = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.parent = mv.transform;
                Switch = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.parent = mv.transform;
                Switch = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.parent = mv.transform;
                Switch = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.parent = mv.transform;
                Switch = false;
            }
        }
    }
}

 

・コマンド初期位置

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

public class StartArrowGenerator : MonoBehaviour
{
    public GameObject Aprefab;
    public GameObject Bprefab;
    public GameObject Uprefab;
    public GameObject Rprefab;
    public GameObject Dprefab;
    public GameObject Lprefab;
    GameObject mv;

    public bool Switch1 = true;
    public bool Switch2 = true;
    public bool Switch3 = true;
    public bool Switch4 = true;
    public bool Switch5 = true;
    public bool Switch6 = true;
    public bool Switch7 = true;
    public bool Switch8 = true;
    public bool Switch9 = true;

    // Start is called before the first frame update
    void Start()
    {
        mv = GameObject.Find("Move");
    }

    // Update is called once per frame
    void Update()
    {
        if (Switch1 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(-3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch1 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(-3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch1 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(-3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch1 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(-3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch1 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(-3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch1 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(-3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch1 = false;
            }
        }

        if (Switch2 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(-2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch2 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(-2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch2 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(-2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch2 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(-2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch2 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(-2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch2 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(-2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch2 = false;
            }
        }

        if (Switch3 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(-1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch3 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(-1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch3 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(-1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch3 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(-1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch3 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(-1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch3 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(-1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch3 = false;
            }
        }

        if (Switch4 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(-0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch4 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(-0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch4 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(-0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch4 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(-0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch4 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(-0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch4 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(-0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch4 = false;
            }
        }

        if (Switch5 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch5 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch5 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch5 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch5 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch5 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(0.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch5 = false;
            }
        }

        if (Switch6 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch6 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch6 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch6 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch6 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch6 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(1.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch6 = false;
            }
        }

        if (Switch7 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch7 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch7 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch7 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch7 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch7 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(2.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch7 = false;
            }
        }

        if (Switch8 == true)
        {
            int dice = Random.Range(1, 12);

            if (dice <= 2)
            {
                GameObject go = Instantiate(Aprefab) as GameObject;
                go.transform.position = new Vector3(3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch8 = false;
            }

            if ((dice >= 3) && (dice <= 4))
            {
                GameObject go = Instantiate(Bprefab) as GameObject;
                go.transform.position = new Vector3(3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch8 = false;
            }

            if ((dice >= 5) && (dice <= 6))
            {
                GameObject go = Instantiate(Uprefab) as GameObject;
                go.transform.position = new Vector3(3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch8 = false;
            }

            if ((dice >= 7) && (dice <= 8))
            {
                GameObject go = Instantiate(Rprefab) as GameObject;
                go.transform.position = new Vector3(3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch8 = false;
            }

            if ((dice >= 9) && (dice <= 10))
            {
                GameObject go = Instantiate(Dprefab) as GameObject;
                go.transform.position = new Vector3(3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch8 = false;
            }

            if (dice >= 11)
            {
                GameObject go = Instantiate(Lprefab) as GameObject;
                go.transform.position = new Vector3(3.5f, 3.5f, 0);
                go.transform.parent = mv.transform;
                Switch8 = false;
            }
        }
    }
}

 

・肉処理

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

public class MeatController : MonoBehaviour
{
    Rigidbody2D rigid2D;
    bool Switch = true;
    int x;
    int y;
    int z;

    void Start()
    {
        rigid2D = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        x = Random.Range(2, 4);
        y = Random.Range(2, 4);

        if (Switch == true)
        {
            Vector3 force = new Vector3(x, y, 0);
            rigid2D.AddForce(force, ForceMode2D.Impulse);
            Switch = false;
        }

        Destroy(gameObject, 5.0f);
    }
}

 

肉ジェネレーター

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

public class MeatGenerator : MonoBehaviour
{
    GameObject mv;
    public GameObject MeatPrefab;

    void Start()
    {
        mv = GameObject.Find("Move");
    }

    void Update()
    {
        if (mv.GetComponent<Move>().MeatSwitch == true)
        {
            GameObject go = Instantiate(MeatPrefab) as GameObject;
            mv.GetComponent<Move>().MeatSwitch = false;
        }
    }
}