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

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

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

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

Unity

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

Q&A

解決済

1回答

6379閲覧

【Unity・C#】Unityのタップゲームの作成において【No overload for method 'Instantiate' takes 0 arguments】のエラーが表示される

muuu_u

総合スコア7

C#

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

Unity

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

0グッド

0クリップ

投稿2020/02/16 04:46

前提・実現したいこと

Unity初心者です。
本を参考にタップゲームを作成しようとしているのですが、
エラー文で詰まってしまっております。

発生している問題・エラーメッセージ

Unityのコンソールで以下のような文がエラーとして出ております。

Assets/Scripts/GameManager.cs(140,42): error CS1501: No overload for method 'Instantiate' takes 0 arguments

該当のソースコード

C#

1sing System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5using UnityEngine.UI; 6using System; 7 8public class GameManager : MonoBehaviour { 9//定数定義 10private const int MAX_ORB = 10; //オーブ最大数 11private const int RESPAWN_TIME = 5; //オーブが発生する秒数 12private const int MAX_LEVEL = 2; //最大レベル 13 14//オブジェクト参照 15public GameObject orbPrefab; //オーブのプレハブ指定 16public GameObject lvupPrefab; //レベルアップ時のエフェクト 17public GameObject canvasGame; //ゲームキャンバス 18public GameObject textScore; //スコアテキスト 19public GameObject lvupImage; //レベルアップイラスト 20public GameObject clearEffectPrefab; //ゲームをクリアした際のエフェクト 21 22//メンバ変数 23private int score = 0; //現在のスコア 24private int nextScore = 10; //レベルアップまでに必要なスコア 25 26private int currentOrb = 0; //現在のオーブ数 27 28private int levelRank = 0; //レベルランク 29 30private DateTime lastDateTime; //前回のオーブを生成した時間 31 32private int [] nextScoreTable = new int[] {10, 10, 10} ; //レベルアップ数 33 34 // Start is called before the first frame update 35 void Start() { 36 //初期オーブ生成 37 currentOrb = 10; 38 for (int i = 0; i < currentOrb; i++) { 39 CreateOrb (); 40 } 41 42 //初期設定(スタートメソッド内で画像を初期状態へセットする。 43 lastDateTime = DateTime.UtcNow; 44 nextScore = nextScoreTable [levelRank]; 45 lvupImage.GetComponent<ObjectManager> ().SetLvupPicture(levelRank); 46 47 RefreshScoreText (); 48 } 49 50 // Update is called once per frame 51 void Update() { 52 if (currentOrb < MAX_ORB) { 53 TimeSpan timeSpan = DateTime.UtcNow - lastDateTime; 54 55 if(timeSpan >= TimeSpan.FromSeconds (RESPAWN_TIME)) { 56 while (timeSpan >= TimeSpan.FromSeconds (RESPAWN_TIME)) { 57 createNewOrb (); 58 timeSpan -= TimeSpan.FromSeconds (RESPAWN_TIME); 59 } 60 } 61 62 } 63 } 64 65 66 //新しいオーブの生成 67 public void createNewOrb () { 68 lastDateTime = DateTime.UtcNow; 69 if (currentOrb >= MAX_ORB) { 70 return; 71 } 72 CreateOrb (); 73 currentOrb++; 74 } 75 76 //オーブ生成 77 public void CreateOrb () { 78 GameObject orb = (GameObject)Instantiate (orbPrefab); 79 orb.transform.SetParent (canvasGame.transform, false); 80 orb.transform.localPosition = new Vector3 ( 81 UnityEngine.Random.Range (-300.0f, 300.0f), 82 UnityEngine.Random.Range (-140.0f, -500.0f), 83 0f); 84 } 85 86 //オーブ入手 87 public void GetOrb () { 88 score += 1; 89 90 // レベルアップ値を越えないよう制限 91 if (score > nextScore) { 92 score = nextScore; 93 } 94 95 LevelUpEffect (); 96 RefreshScoreText (); 97 98 //ゲームクリア判定 99 if ((score == nextScore) && (levelRank == MAX_LEVEL)) { 100 LevelMax (); 101 } 102 103 currentOrb--; 104 } 105 106 //スコアテキスト更新 107 void RefreshScoreText () { 108 textScore.GetComponent<Text> ().text = 109 "オーブ: " + score + " / " + nextScore; 110 } 111 112 //画像のレベル管理 113 void LevelUp () { 114 if (score >= nextScore) { 115 if (levelRank < MAX_LEVEL) { 116 levelRank++; 117 score = 0; 118 119 LevelUpEffect (); 120 121 nextScore = nextScoreTable [levelRank]; 122 lvupImage.GetComponent<ObjectManager> ().SetLvupPicture (levelRank); 123 124 } 125 } 126 } 127 128 //レベルアップ時の演出 129 void LevelUpEffect () { 130 GameObject lvupEf = (GameObject)Instantiate (lvupPrefab); 131 132 lvupEf.transform.SetParent(canvasGame.transform, false); 133 lvupEf.transform.SetSiblingIndex (2); 134 135 Destroy (lvupEf, 0.5f); 136 } 137 138 //レベルが限界値まで到達した時の演出 139 void LevelMax () { 140 GameObject clearEf = (GameObject)Instantiate (); 141 clearEf.transform.SetParent (canvasGame.transform, false); 142 } 143}

試したこと

【No overload for method 'Instantiate' takes 0 arguments】

のワードで検索をかけました、メソッドのインスタンスの引数が取れていないようなエラーとなっております。
レベルアップ周りの記述がうまくいっていないような感じがするのですが、
知識が浅く自分でのコードの問題点に気づく事ができません、宜しければご回答宜しくお願い致します。

補足情報(FW/ツールのバージョンなど)

Unity2019.2.5.f1

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

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

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

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

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

guest

回答1

0

自己解決

すみません、自己解決しました。

GameObject clearEf = (GameObject)Instantiate ();

引数の部分が空になっていたので、エラーが発生していたようです。
カッコ内にclearEffectPrefabを記載するとエラーが解決しました。

sing System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; public class GameManager : MonoBehaviour { //定数定義 private const int MAX_ORB = 10; //オーブ最大数 private const int RESPAWN_TIME = 5; //オーブが発生する秒数 private const int MAX_LEVEL = 2; //最大レベル //オブジェクト参照 public GameObject orbPrefab; //オーブのプレハブ指定 public GameObject lvupPrefab; //レベルアップ時のエフェクト public GameObject canvasGame; //ゲームキャンバス public GameObject textScore; //スコアテキスト public GameObject lvupImage; //レベルアップイラスト public GameObject clearEffectPrefab; //ゲームをクリアした際のエフェクト //メンバ変数 private int score = 0; //現在のスコア private int nextScore = 10; //レベルアップまでに必要なスコア private int currentOrb = 0; //現在のオーブ数 private int levelRank = 0; //レベルランク private DateTime lastDateTime; //前回のオーブを生成した時間 private int [] nextScoreTable = new int[] {10, 10, 10} ; //レベルアップ数 // Start is called before the first frame update void Start() { //初期オーブ生成 currentOrb = 10; for (int i = 0; i < currentOrb; i++) { CreateOrb (); } //初期設定(スタートメソッド内で画像を初期状態へセットする。 lastDateTime = DateTime.UtcNow; nextScore = nextScoreTable [levelRank]; lvupImage.GetComponent<ObjectManager> ().SetLvupPicture(levelRank); RefreshScoreText (); } // Update is called once per frame void Update() { if (currentOrb < MAX_ORB) { TimeSpan timeSpan = DateTime.UtcNow - lastDateTime; if(timeSpan >= TimeSpan.FromSeconds (RESPAWN_TIME)) { while (timeSpan >= TimeSpan.FromSeconds (RESPAWN_TIME)) { createNewOrb (); timeSpan -= TimeSpan.FromSeconds (RESPAWN_TIME); } } } } //新しいオーブの生成 public void createNewOrb () { lastDateTime = DateTime.UtcNow; if (currentOrb >= MAX_ORB) { return; } CreateOrb (); currentOrb++; } //オーブ生成 public void CreateOrb () { GameObject orb = (GameObject)Instantiate (orbPrefab); orb.transform.SetParent (canvasGame.transform, false); orb.transform.localPosition = new Vector3 ( UnityEngine.Random.Range (-300.0f, 300.0f), UnityEngine.Random.Range (-140.0f, -500.0f), 0f); } //オーブ入手 public void GetOrb () { score += 1; // レベルアップ値を越えないよう制限 if (score > nextScore) { score = nextScore; } LevelUpEffect (); RefreshScoreText (); //ゲームクリア判定 if ((score == nextScore) && (levelRank == MAX_LEVEL)) { LevelMax (); } currentOrb--; } //スコアテキスト更新 void RefreshScoreText () { textScore.GetComponent<Text> ().text = "オーブ: " + score + " / " + nextScore; } //画像のレベル管理 void LevelUp () { if (score >= nextScore) { if (levelRank < MAX_LEVEL) { levelRank++; score = 0; LevelUpEffect (); nextScore = nextScoreTable [levelRank]; lvupImage.GetComponent<ObjectManager> ().SetLvupPicture (levelRank); } } } //レベルアップ時の演出 void LevelUpEffect () { GameObject lvupEf = (GameObject)Instantiate (lvupPrefab); lvupEf.transform.SetParent(canvasGame.transform, false); lvupEf.transform.SetSiblingIndex (2); Destroy (lvupEf, 0.5f); } //レベルが限界値まで到達した時の演出 void LevelMax () { GameObject clearEf = (GameObject)Instantiate (clearEffectPrefab); clearEf.transform.SetParent (canvasGame.transform, false); } }

投稿2020/02/16 05:33

muuu_u

総合スコア7

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問