実現したいこと
gamecanvasを用いた、8*8マスの簡単なオセロゲームを作りたいのですが、エラーが出てしまいます。できたものは、学校での授業の期末課題として提出する予定です。
インターネットの情報などを参照しながら組み立てた初心者のコードです。的外れな質問をしていたらごめんなさい。
発生している問題・分からないこと
UNITYで実行しようとしたところ、以下のようなエラーメッセージが出ました。
エラーメッセージ
error
1All compiler errors have to be fixed before you can enter playmode! 2UnityEditor.SceneView:ShowCompileErrorNotification () (at /Users/bokken/build/output/unity/unity/Editor/Mono/SceneView/SceneView.cs:3919) 3 4Assets/Game.cs(31,23): error CS1061: 'IGameCanvas' does not contain a definition for 'width' and no accessible extension method 'width' accepting a first argument of type 'IGameCanvas' could be found (are you missing a using directive or an assembly reference?) 5 6Assets/Game.cs(53,16): error CS1061: 'IGameCanvas' does not contain a definition for 'GetPointerDown' and no accessible extension method 'GetPointerDown' accepting a first argument of type 'IGameCanvas' could be found (are you missing a using directive or an assembly reference?) 7 8Assets/Game.cs(55,46): error CS1061: 'IGameCanvas' does not contain a definition for 'pointerX' and no accessible extension method 'pointerX' accepting a first argument of type 'IGameCanvas' could be found (are you missing a using directive or an assembly reference?) 9 10Assets/Game.cs(56,46): error CS1061: 'IGameCanvas' does not contain a definition for 'pointerY' and no accessible extension method 'pointerY' accepting a first argument of type 'IGameCanvas' could be found (are you missing a using directive or an assembly reference?) 11 12Assets/Game.cs(78,81): error CS1503: Argument 5: cannot convert from 'UnityEngine.Color' to 'float' 13 14Assets/Game.cs(82,81): error CS1503: Argument 5: cannot convert from 'UnityEngine.Color' to 'float' 15 16Assets/Game.cs(86,20): error CS1061: 'IGameCanvas' does not contain a definition for 'StrokeRect' and no accessible extension method 'StrokeRect' accepting a first argument of type 'IGameCanvas' could be found (are you missing a using directive or an assembly reference?) 17 18
該当のソースコード
#nullable enable using GameCanvas; using Unity.Mathematics; using UnityEngine; using UnityEngine.InputSystem; /// <summary> /// ゲームクラス /// </summary> public sealed class Game : GameBase { // グリッドのサイズ private const int gridSize = 8; // セルのサイズ private float cellSize; // 盤面 private int[,] board = new int[gridSize, gridSize]; // 現在のプレイヤー(1: 黒, 2: 白) private int currentPlayer = 1; /// <summary> /// 初期化処理 /// </summary> public override void InitGame() { // キャンバスの大きさを設定します gc.ChangeCanvasSize(640, 640); // セルのサイズを計算 cellSize = gc.width / gridSize; // 盤面の初期化 for (int i = 0; i < gridSize; i++) { for (int j = 0; j < gridSize; j++) { board[i, j] = 0; } } // 初期配置 board[3, 3] = board[4, 4] = 1; board[3, 4] = board[4, 3] = 2; } /// <summary> /// 動きなどの更新処理 /// </summary> public override void UpdateGame() { // マウスがクリックされたら石を置く if (gc.GetPointerDown()) { int mouseX = Mathf.FloorToInt(gc.pointerX / cellSize); int mouseY = Mathf.FloorToInt(gc.pointerY / cellSize); if (IsValidMove(mouseX, mouseY)) { PlaceStone(mouseX, mouseY); SwitchPlayer(); } } } /// <summary> /// 描画の処理 /// </summary> public override void DrawGame() { // 盤面の描画 for (int i = 0; i < gridSize; i++) { for (int j = 0; j < gridSize; j++) { if (board[i, j] == 1) { gc.FillRect(i * cellSize, j * cellSize, cellSize, cellSize, Color.black); } else if (board[i, j] == 2) { gc.FillRect(i * cellSize, j * cellSize, cellSize, cellSize, Color.white); } // グリッド線の描画 gc.StrokeRect(i * cellSize, j * cellSize, cellSize, cellSize, Color.black); } } } // 石を置く処理 private void PlaceStone(int x, int y) { board[x, y] = currentPlayer; } // プレイヤーの切り替え private void SwitchPlayer() { currentPlayer = (currentPlayer == 1) ? 2 : 1; } // その位置に石を置けるかどうかの判定 private bool IsValidMove(int x, int y) { return (board[x, y] == 0); } }
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
chatgptに、エラーメッセージとコードを添えて問題点を聞いてみましたが、的確な回答を得られませんでした。
補足
特になし

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。