実現したいこと
ここに実現したいことを箇条書きで書いてください。
- 3Dゲームにて、UIとしてフィールド上に存在するItemの個数を表示したい。UnitychanがItemを取得していく度に、1つずつ表示される残りItem数が減るようにしたい。
前提
ここに質問の内容を詳しく書いてください。
Unityにて、UnitychanがItemに接触して収集する3Dゲームシステムを作っています。
言語はC#、ソースコードはVisualStudioで書いております。
Unitychanは公式の無料asset、Cube等は「ステップアップUnity プロが教える現場の教科書」のP65,66をほぼそっくりそのまま書いております。
エラーメッセージは表示されていないのですが、UnitychanがItemに接触しても取得することができず、どうしたものかと相談に来ました。
追記できるようでしたら、都度情報を追加していきますが、いったん手持ちのわかる範囲でお見せしております。
発生している問題・エラーメッセージ
エラーメッセージ
Assets\Game.cs(16,13): error CS0246: The type or namespace name 'UnityChanControlScriptWithRgidBody' could not be found (are you missing a using directive or an assembly reference?)
該当のソースコード
ソースコード using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MyScript : MonoBehaviour { // 生成するアイテムの総数 public const int Total = 10; private int _restCount; [SerializeField] private TMPro.TMP_Text _restCountText; [SerializeField] private UnityChanControlScriptWithRgidBody _player; [SerializeField] private GameObject _itemPrefab; void Start() { SetRestCount(Total); CreateItems(); // OnGetItemCallbackにOnGetItemを登録 _player.OnGetItemCallback += OnGetItem; } void Update() { } // アイテムを生成 private void CreateItems() { for (int i = 0; i < Total; i++) { GameObject item = Instantiate(_itemPrefab); item.transform.position = GetRamdomItemPosition(); } } // ランダムにアイテムを配置する座標を返す private Vector3 GetRamdomItemPosition() { //1f~3.5fの間でランダムにx座標を決定// var x = UnityEngine.Random.Range(1f, 5f); // 1/2の確率で反転// if (UnityEngine.Random.Range(0, 2) % 2 == 0) { x *= -1f; } //1f~3.5fの間でランダムにz座標を決定// var z = UnityEngine.Random.Range(1f, 5f); // 1/2の確率で反転// if (UnityEngine.Random.Range(0, 2) % 2 == 0) { z *= -1f; } return new Vector3(x, 0f, z); } private void SetRestCount(int value) { _restCount = value; _restCountText.text = string.Format("残り{0}個", _restCount); } private void OnGetItem() { SetRestCount(_restCount - 1); } }
試したこと
ChatGPTで試行錯誤
ただしCS0246とCS1061以下の堂々巡り。
error CS0246
The type or namespace name 'UnityChanControlScriptWithRgidBody' could not be found (are you missing a using directive or an assembly reference?)
error CS1061
'Player' does not contain a definition for 'OnGetItemCallback' and no accessible extension method 'OnGetItemCallback' accepting a first argument of type 'Player' could be found (are you missing a using directive or an assembly reference?)
補足情報(FW/ツールのバージョンなど)
操作キャラのスクリプト
ファイル名UnityChanControlScriptWithRgidBody.cs
using UnityEngine;
using System.Collections;
using System.Diagnostics;
using System;
namespace UnityChan
public class UnityChanControlScriptWithRgidBody : MonoBehaviour
{
//略//
public Action OnGetItemCallback;
}

回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。