大学の課題でゲームを制作している者です。
一定数のアイテムを取得したら、プレイヤーのキャラクターが進化(変化)するというものをif分岐させて SetActive でキャラクターモデルを差し替えたいのですが、以下のようなエラーコードが出てきてしまい、上手くいきません。どのように改善すべきでしょうか??
発生している問題・エラーメッセージ
エラーメッセージ CharaCon.cs(71,13): error CS0103:The name 'Player01' does not exist in the current context CharaCon.cs(77,13): error CS0103:The name 'Player01' does not exist in the current context CharaCon.cs(79,13): error CS0103:The name 'Player02' does not exist in the current context
該当のソースコード
71:Player01.SetActive(false);
77:if (Player01.activeSelf)
79:Player02.SetActive(true);
C#
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class CharaCon : MonoBehaviour
{
public GameObject Wall; public Text countText; private int count; float inputHorizontal; float inputVertical; Rigidbody rb; public float moveSpeed = 3f; // Start is called before the first frame update void Start() { rb = GetComponent<Rigidbody>(); count = 0; SetCountText(); GameObject Player01 = GameObject.Find ("C01"); GameObject Player02 = GameObject.Find ("C02"); } // Update is called once per frame void Update() { inputHorizontal = Input.GetAxisRaw("Horizontal"); inputVertical = Input.GetAxisRaw("Vertical"); } void FixedUpdate() { Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; // 方向キーの入力値とカメラの向きから、移動方向を決定 Vector3 moveForward = cameraForward * (inputVertical) + Camera.main.transform.right * inputHorizontal; rb.velocity = moveForward * moveSpeed + new Vector3(0, rb.velocity.y, 0); } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Item")) { //script.count += 1; other.gameObject.SetActive(false); count = count + 1; SetCountText(); } } void SetCountText() { countText.text = "X" + count.ToString(); if(count >= 3) { Wall.SetActive(false); Player01.SetActive(false); } } void OnDisable() { if (Player01.activeSelf) { Player02.SetActive(true); } }
}
回答1件
あなたの回答
tips
プレビュー