My question probably comes from a bad understanding of inheritance and composition. I have a couple of classes with inheritance BasePlayerClass=>SpaceShipClass=>SpaceShipObject. I dont understand how to call the instantiated class Player from another classes, so that it saves its properties and doesn't get the null value.
public class CreatePlayer : MonoBehaviour
{
public Sprite SCALPEL, WARPER, ORION;
public SpriteRenderer SelectedCharacterSprite;
public Skill_Slot newSkillslot;
private readonly string SelectedCharacter = null;
public void Start()
{
PlayerCreation();
newSkillslot.CreateSkillSlots();
}
public void PlayerCreation()
{
BasePlayerClass player = new BasePlayerClass();
SelectedCharacterSprite = this.GetComponent<SpriteRenderer>();
int getCharacter = PlayerPrefs.GetInt(SelectedCharacter);
switch(getCharacter){
case 0:
SelectedCharacterSprite.sprite = SCALPEL;
player.SpaceshipClass = new ScalpelSpaceship();
break;
case 1:
SelectedCharacterSprite.sprite = WARPER;
player.SpaceshipClass = new WarperSpaceship();
break;
case 2:
SelectedCharacterSprite.sprite = ORION;
player.SpaceshipClass = new OrionSpaceship();
break;
}
}
}
public class Skill_Slot : MonoBehaviour
{
public Skill SignedSkill;
private Image qImg;
private Image wImg;
private Image eImg;
public GameObject qSkillSlot;
public GameObject wSkillSlot;
public GameObject eSkillSlot;
public BasePlayerClass player;
public void CreateSkillSlots()
{
Debug.Log(player.SpaceshipClass);
qImg = qSkillSlot.GetComponent<Image>();
wImg = wSkillSlot.GetComponent<Image>();
SignedSkill = player.SpaceshipClass.QSkill;
switch(player.SpaceshipClass.QSkill.SkillIndex){
case 1:
qImg.sprite = Resources.Load<Sprite>("BasicAttack");
SignedSkill = player.SpaceshipClass.QSkill;
break;
case 2:
qImg.sprite = Resources.Load<Sprite>("OrionMove");
break;
case 3:
break;
}
switch(player.SpaceshipClass.WSkill.SkillIndex){
case 1:
wImg.sprite = Resources.Load<Sprite>("BasicAttack");
break;
case 2:
wImg.sprite = Resources.Load<Sprite>("OrionMove");
SignedSkill = player.SpaceshipClass.WSkill;
break;
case 3:
break;
}
}
}