RedHand
New member
- Joined
- Mar 1, 2021
- Messages
- 3
- Programming Experience
- Beginner
I'm writing a code that is trying to access the backSprite and frontSprite, but it gives me an error CS0122. Can anyone help?
This is for Unity. The error is: Assets\Script\Battle\BattleUnit.cs(16,57): error CS0122: 'MonsterBase.frontSprite' is inaccessible due to its protection level
and Assets\Script\Battle\BattleUnit.cs(14,57): error CS0122: 'MonsterBase.backSprite' is inaccessible due to its protection level
This is for Unity. The error is: Assets\Script\Battle\BattleUnit.cs(16,57): error CS0122: 'MonsterBase.frontSprite' is inaccessible due to its protection level
and Assets\Script\Battle\BattleUnit.cs(14,57): error CS0122: 'MonsterBase.backSprite' is inaccessible due to its protection level
C#:
public class BattleUnit : MonoBehaviour
{
[SerializeField] MonsterBase _base;
[SerializeField] int level;
[SerializeField] bool isPlayerUnit;
public Monster monster { get; set; }
public void Setup()
{
monster = new Monster(_base, level);
if (isPlayerUnit)
GetComponent<Image>().sprite = monster.Base.backSprite;
else
GetComponent<Image>().sprite = monster.Base.frontSprite;
}
C#:
public class MonsterBase : ScriptableObject
{
[SerializeField] string name;
[TextArea]
[SerializeField] string description;
[SerializeField] Sprite backSprite;
[SerializeField] Sprite frontSprite;
Last edited: