前提
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ここにより詳細な情報を記載してください。
> classを使っていませんので
MoveRightの定義(中身)はどこですか?
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の中身がないのでしょうか?
無知ですみませんが、よろしくお願いします。
activeBlockはBlockクラスとして定義されています。
BlockクラスにMoveRightがないって言われています。
なるほど、ありがとうございます。
Blockクラスに、Move Rightを加える場合、どこになるのでしょうか?
Move Leftはエラーが出ていませんが、
MoveLeftはBlockクラスにあるのでしょうか?
他のスクリプトファイルに
Move Rightがない箇所を見つけました。解決できるかもしれません。
解決できました!わかりやすい回答ありがとうございました!
心から感謝申し上げます。

回答1件
あなたの回答
tips
プレビュー