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

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

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

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

Q&A

解決済

1回答

738閲覧

Unity C# テトリス エラーCS1061

baby-d

総合スコア2

C#

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

1グッド

0クリップ

投稿2023/01/20 02:25

前提

Unityで C#を使い、テトリスゲームを作っています。

エラーが出ているので解決したいです。

実現したいこと

このボタンを押したら右に回転などの
ブロックの操作を行うプログラムを作成したいです。

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

コンパイルエラー CS1061 'Block' does not contain a definition for 'MoveRight' and no accessible extension method 'MoveRight' accepting a first argument of type 'Block' could be found (are you missing a using directive or an assembly reference?) 'Block' には 'MoveRight' の定義が含まれておらず、タイプ 'Block' の最初の引数を受け入れるアクセス可能な拡張メソッド 'MoveRight' が見つかりませんでした (using ディレクティブまたはアセンブリ参照がありませんか?)

該当のソースコード

C#

1ソースコード 2```void PlayerInput() 3 { 4 if(Input.GetKey(KeyCode.D) && (Time.time > nextKeyLeftRightTimer) 5 || Input.GetKeyDown(KeyCode.D)) 6 { 7 activeBlock.MoveRight(); 8 9 nextKeyLeftRightTimer = Time.time + nextKeyLeftRightInterval; 10 11 if(!board.CheckPosition(activeBlock)) 12 { 13 activeBlock.MoveLeft(); 14 } 15 } 16 else if(Input.GetKey(KeyCode.A) && (Time.time > nextKeyLeftRightTimer) || Input.GetKeyDown(KeyCode.A)) 17 { 18 activeBlock.MoveLeft(); 19 20 nextKeyLeftRightTimer = Time.time + nextKeyLeftRightInterval; 21 22 if(!board.CheckPosition(activeBlock)) 23 { 24 activeBlock.MoveRight(); 25 } 26 } 27 28 else if(Input.GetKey(KeyCode.E) && (Time.time > nextKeyRotateTimer)) 29 { 30 activeBlock.RotateRight(); 31 nextKeyRotateTimer = Time.time + nextKeyRotateInterval; 32 33 if(!board.CheckPosition(activeBlock)) 34 { 35 activeBlock.RotateLeft(); 36 } 37 } 38 39 else if(Input.GetKey(KeyCode.S) && (Time.time > nextKeyDownTimer) 40 || (Time.time > nextdropTimer)) 41 { 42 activeBlock.MoveDown(); 43 44 nextKeyDownTimer = Time.time + nextKeyDownInterval; 45 nextdropTimer = Time.time + dropInterval; 46 47 if(!board.CheckPosition(activeBlock)) 48 { 49 BottomBoard(); 50 } 51 } 52 } 53 54### 試したこと 55 56調べると、classに対しての定義の話が多く出てきたのですが 57classを使っていませんので、よくわかりません。 58スペルミスではないと思います。 59 60### 補足情報(FW/ツールのバージョンなど) 61 62ここにより詳細な情報を記載してください。
baby-d👍を押しています

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

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

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

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

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

ozwk

2023/01/20 02:28 編集

> classを使っていませんので MoveRightの定義(中身)はどこですか?
baby-d

2023/01/20 02:40

using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameManager : MonoBehaviour { Spawner spawner; Block activeBlock; [SerializeField] private float dropInterval = 0.25f; float nextdropTimer; Board board; float nextKeyDownTimer,nextKeyLeftRightTimer,nextKeyRotateTimer; [SerializeField] private float nextKeyDownInterval,nextKeyLeftRightInterval,nextKeyRotateInterval; private void Start() { spawner = GameObject.FindObjectOfType<Spawner>(); board = GameObject.FindObjectOfType<Board>(); spawner.transform.position = Rounding.Round(spawner.transform.position); nextKeyDownTimer = Time.time + nextKeyDownInterval; nextKeyLeftRightTimer = Time.time + nextKeyLeftRightInterval; nextKeyRotateTimer = Time.time + nextKeyRotateInterval; if(!activeBlock) { activeBlock = spawner.SpawnBlock(); } } private void Update() { PlayerInput(); } void PlayerInput() { if(Input.GetKey(KeyCode.D) && (Time.time > nextKeyLeftRightTimer) || Input.GetKeyDown(KeyCode.D)) { activeBlock.MoveRight(); nextKeyLeftRightTimer = Time.time + nextKeyLeftRightInterval; if(!board.CheckPosition(activeBlock)) { activeBlock.MoveLeft(); } } else if(Input.GetKey(KeyCode.A) && (Time.time > nextKeyLeftRightTimer) || Input.GetKeyDown(KeyCode.A)) { activeBlock.MoveLeft(); nextKeyLeftRightTimer = Time.time + nextKeyLeftRightInterval; if(!board.CheckPosition(activeBlock)) { activeBlock.MoveRight(); } } else if(Input.GetKey(KeyCode.E) && (Time.time > nextKeyRotateTimer)) { activeBlock.RotateRight(); nextKeyRotateTimer = Time.time + nextKeyRotateInterval; if(!board.CheckPosition(activeBlock)) { activeBlock.RotateLeft(); } } else if(Input.GetKey(KeyCode.S) && (Time.time > nextKeyDownTimer) || (Time.time > nextdropTimer)) { activeBlock.MoveDown(); nextKeyDownTimer = Time.time + nextKeyDownInterval; nextdropTimer = Time.time + dropInterval; if(!board.CheckPosition(activeBlock)) { BottomBoard(); } } } void BottomBoard() { activeBlock.MoveUp(); board.SaveBlockInGrid(activeBlock); activeBlock = spawner.SpawnBlock(); nextKeyDownTimer = Time.time; nextKeyLeftRightTimer = Time.time; nextKeyRotateTimer = Time.time; } } これがこのファイルのすべてのコーデです。 MoveRightの中身がないのでしょうか? 無知ですみませんが、よろしくお願いします。
YAmaGNZ

2023/01/20 03:51

activeBlockはBlockクラスとして定義されています。 BlockクラスにMoveRightがないって言われています。
baby-d

2023/01/20 03:55

なるほど、ありがとうございます。 Blockクラスに、Move Rightを加える場合、どこになるのでしょうか? Move Leftはエラーが出ていませんが、 MoveLeftはBlockクラスにあるのでしょうか?
baby-d

2023/01/20 03:57

他のスクリプトファイルに Move Rightがない箇所を見つけました。解決できるかもしれません。
baby-d

2023/01/20 03:58

解決できました!わかりやすい回答ありがとうございました! 心から感謝申し上げます。
guest

回答1

0

自己解決

active block のなかに Right Moveが定義されていない とのことでしたが
active block は Block として定義されていましたので

変換すると Blockクラスに Right Moveの定義がない。というエラーでした。

Block という他のスクリプトファイルの中に
Blockクラスがあり、その中にRight Moveの定義が抜けておりましたので
追加したところ、エラーは解決しました。

投稿2023/01/20 04:01

baby-d

総合スコア2

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問