質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

951閲覧

Unityでinstanceが呼び出せず困っています。

EllyTakayama

総合スコア2

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2021/06/16 02:28

unityでゲームを作成しております。
GameOverPanelのスライドインが終了した時点で
DOTweenのコールバックでpfefab化したフードをFoodGenerator.csで呼び出したいのですがうまくいきません。

アドバイスをお願い致します。

以下2つのスクリプトです。

D0TweenPanel.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.UI;
//DoTweenでGameOverPanelをスライドいんさせるスクリプト0608
public class DOTweenPanel : MonoBehaviour
{
public GameObject gameOverPanel;
public GameObject gradePanel;

// Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void DoGameOverPanel(){ gameOverPanel.GetComponent<RectTransform>() .DOAnchorPos(new Vector2(0,0), 1.5f) .SetEase(Ease.OutBack) .OnComplete(() => { FoodGenerator.instance.Spawn(); }) ; }

}


FoodGenerator.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//GameOver画面であげるフードを生成するスクリプト0525

public class FoodGenerator : MonoBehaviour
{
public static FoodGenerator instance;
public int foodCount;
public bool isOneTimeFood;
public GameObject[] foodPrefab;
private int number;

void Awake()
{
MakeInstance();
}

void MakeInstance() { if (instance == null) { instance = this; } } void Start(){ foodCount = 0; } // Update is called once per frame void Update() {

  
}
public void Spawn(){
if(foodCount < GameManager.singleton.currentScore){
number = Random.Range(0,foodPrefab.Length);
//foodPrefabの配列の中からランダムにフードを生成

Instantiate(foodPrefab[number], transform.position, transform.rotation); } foodCount++; //FoodGeneratorと同じ位置にPrefabを生成する }

}


何卒よろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

GameOverPanelのスライドインの前の処理で
GameManager.currentScoreが0になってしまっており
インスタンスを呼び出ししてもメソッドが実行されない状態でした。
お手数おかけし申し訳ありませんでした。

投稿2021/06/16 03:01

EllyTakayama

総合スコア2

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問