0

Unityに関する質問です。

ステージ生成オブジェクトを作る | Unityでゲームを作ろう!

上記ページを参考にゲームを作ってるのですが、ステージを作るページのところでEmitterのスクリプトを制作しても壁が繰り返し登場しません。

それと上のサイトではEmitterのスクリプトはどうやらWall Emitterにアタッチするらしいのですが、Wall Emitterがどこかわかりません。解決策を教えてくれると幸いです。
ちなみにスクリプトは上のウェブサイトにあったコードをそのまま使っています

Emitterのプログラム

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

public class Emitter : MonoBehaviour
{

    [SerializeField]
    float emitWaitTimeMin = 0.6f;
    [SerializeField]
    float emitWaitTimeMax = 1.0f;
    [SerializeField]
    float intervalCofficient = 0.98f; //レベルアップしたとき、生成間隔を何倍するかの係数
    [SerializeField]
    float wallSpawnX = 11.0f;
    [SerializeField]
    float wallSpawnY = -2.5f;
    [SerializeField]
    GameObject wall;
    [SerializeField]
    GameManager gameManager;

    bool emitterEnabled = true;
    int cullentLevel;
    float emitWaitTimeMinNow;
    float emitWaitTimeMaxNow;

    //毎フレームの処理
    void Update()
    {
        //タイトルまたはゲームオーバー画面
        if (!gameManager.playing)
        {
            //初期化
            cullentLevel = gameManager.level;
            emitWaitTimeMinNow = emitWaitTimeMin;
            emitWaitTimeMaxNow = emitWaitTimeMax;
        }

        //プレイ中の処理
        if (emitterEnabled && gameManager.playing)
        {
            //生成処理
            Instantiate(wall, new Vector3(wallSpawnX, wallSpawnY, transform.position.z), Quaternion.identity);

            StartCoroutine(EmitWait());

            //レベルアップ時に生成速度Up
            if (gameManager.level != cullentLevel)
            {
                emitWaitTimeMinNow *= intervalCofficient;
                emitWaitTimeMaxNow *= intervalCofficient;
                cullentLevel = gameManager.level;
            }
        }
    }

    //生成を待つ処理
    IEnumerator EmitWait()
    {
        emitterEnabled = false;
        float emitWaitTime = Random.Range(emitWaitTimeMinNow, emitWaitTimeMaxNow);
        yield return new WaitForSeconds(emitWaitTime);
        emitterEnabled = true;
    }
}

Wallのプログラム

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

public class Wall : MonoBehaviour
{

    [SerializeField]
    float speed = 10.0f;
    [SerializeField]
    float minScaleX = 4.0f;
    [SerializeField]
    float minScaleY = 3.0f;
    [SerializeField]
    float maxScaleX = 6.0f;
    [SerializeField]
    float maxScaleY = 7.0f;

    bool inCamera = false;
    Rigidbody2D rigidBody2D;

    //初期化
    void Start()
    {
        //コンポーネントを取得
        rigidBody2D = GetComponent<Rigidbody2D>();

        //壁の長さをランダムに変更
        float scaleX = Random.Range(minScaleX, maxScaleX);
        float scaleY = Random.Range(minScaleY, maxScaleY);
        transform.localScale = new Vector3(scaleX, scaleY, transform.localScale.z);
    }

    //物理演算
    void FixedUpdate()
    {
        rigidBody2D.velocity = Vector2.left * speed;
    }

    //消去処理
    public void DestroyBlock()
    {
        Destroy(gameObject);
    }

    //カメラ内外の判定処理
    void OnBecameVisible()
    {
        inCamera = true;
    }

    void OnBecameInvisible()
    {
        //一度画面内に入って、また出たときに消去する
        if (inCamera)
        {
            DestroyBlock();
        }
    }
}
3
  • 回答される方へ detail.chiebukuro.yahoo.co.jp/qa/question_detail/q12220369577
    – htb
    2020年2月18日 5:55
  • 本質的な部分ではありませんが、「このサイトでゲームを作ってる」と「このサイト(を参考に)ゲームを作ってる」では意味合いが違ってきます。
    – cubick
    2020年2月18日 6:03
  • @cubick すみませんでした。修正しておきます 2020年2月18日 8:19

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。