前提
unityでキャラクターの選択画面を作ろうとしています。
PlayerPrefsで保存したKeyのValueがあるか確認し、キャラクターを指定すると言うものです。
実現したいこと
エラーの解決
発生している問題・エラーメッセージ
Assets\GameManager.cs(16,29): error CS0119: 'PlayerPrefs' is a type, which is not valid in the given context
該当のソースコード
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
[SerializeField] GameObject CharaPrefabs;
// Start is called before the first frame update void Start() { if (PlayerPrefs.HasKey("CHARA_NUMBER")) { if (PlayerPrefs.GetInt("CHARA_NUMBER") == 0) { Instantiate(PlayerPrefs[PlayerPrefs.GetInt("CHARA_NUMBER")], new Vector3(0, 0, 0), Quaternion.identity); } if (PlayerPrefs.GetInt("CHARA_NUMBER") == 1) { Instantiate(PlayerPrefs[PlayerPrefs.GetInt("CHARA_NUMBER")], new Vector3(0, 0, 0), Quaternion.identity); } if (PlayerPrefs.GetInt("CHARA_NUMBER") == 2) { Instantiate(PlayerPrefs[PlayerPrefs.GetInt("CHARA_NUMBER")], new Vector3(0, 0, 0), Quaternion.identity); } } } // Update is called once per frame void Update() { }
}
試したこと
書き間違えがないかなどの確認。
補足情報(FW/ツールのバージョンなど)
unity2021.3.7f1

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/08/17 13:59