前提
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