나는 dcript에 공개 개체를 추가 할 수 없습니다. 무엇입니다 ...스크립트에 사용자 정의 개체 추가
public class Player : MonoBehaviour {
public string charName = "";
public int currentLevel = 0;
public int experiense = 0;
public int strength = 1;
public int agility = 1;
public int maxHealth = 30;
public float currentHealth = 30;
public int maxActionPoints = 5;
public int currentLevelPoints = 10;}
내가
public class CharManager : MonoBehaviour {
public GameObject currentCharacter;
public GameObject charMenu;
public Player currentPlayerStats;
public void changeCharacter(GameObject character)
{
if (currentCharacter){
saveCharacter();
}
currentCharacter = character;
loadSavedInfo();
}
void loadSavedInfo()
{
string playerJson = "";
if (currentCharacter.tag== "Man")
{
if (File.Exists(Application.persistentDataPath +"/Char1.json"))
{
playerJson = File.ReadAllText(Application.persistentDataPath +"/Char1.json");
}
}
else
{
if (File.Exists(Application.persistentDataPath +"/Char2.json"))
{
playerJson = File.ReadAllText(Application.persistentDataPath +"/Char2.json");
}
}
if (playerJson != string.Empty)
{
Player thePlayer = JsonConvert.DeserializeObject<Player>(playerJson);
currentPlayerStats = thePlayer;
}
else
{
currentPlayerStats = gameObject.AddComponent<Player>() as Player;
}
}
이 코드는 새로운 선수 구성 요소를 추가하고 currentPlayerStats이 클래스 CharManager이
이 클래스와 공용 속성을 추가 할 다른 스크립트가 : 코드가있다 내가 잘못 했니? 도움을 주셔서 감사합니다.
여기에서 복사 한 코드에서 Player 클래스가 MonoBehaviour가 아니어야합니다. ..? stat 값만 포함하고 MonoBehaviour가 아닌가? – johnkork
나는 그것을하려고 노력했다. 그래서 어떻게 다른 스크립트에서이 속성을 얻을 수 있습니까? GetComponent가 작동하지 않습니다. – Pavel