Hey im not quite sure this is the right forum to ask but i have have a problem with my code and i cant figure out
whats wrong so maybe you can help me out.
I try to make a card game and wanted to code that the player draws card from its deck, i used a Tutorial and double checked everything but everything seems just like the code in the Tutorial
here are the Error messages
Assets\Scripts\ThisCard.cs(48,31): error CS0120: An object reference is required for the non-static field, method, or property ‘PlayerDeck.deckSize’
Assets\Scripts\ThisCard.cs(159,13): error CS0120: An object reference is required for the non-static field, method, or property ‘PlayerDeck.deckSize’
here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ThisCard : MonoBehaviour
{
public List<Card> thisCard = new List<Card>();
public int thisId;
public int id;
public string cardName;
public int cost;
public string element;
public int power;
public string race;
public string effekt2;
public string cardDescription;
public Sprite thisSprite;
public Image thatImage;
public GameObject legendar;
public GameObject fly;
public GameObject bow;
public Image frame;
public Image rarity;
public Text attackText;
public Text nameText;
public Text raceText;
public Text effektText;
public bool cardBack;
public static bool staticCardBack;
public GameObject Hand;
public int numberOfCardsInDeck;
void Start ()
{
thisCard [0] = CardDataBase.cardList[thisId];
numberOfCardsInDeck = PlayerDeck.deckSize;
}
void Update ()
{
Hand = GameObject.Find("PlayerHand");
if(this.transform.parent == Hand.transform.parent)
{
cardBack = false;
}
id = thisCard[0].id;
power = thisCard[0].power;
cardName = thisCard[0].cardName;
race = thisCard[0].race;
effekt2 = thisCard[0].effekt2;
thisSprite = thisCard[0].thisImage;
attackText.text = " " + power;
nameText.text = " " + cardName;
raceText.text = " " + race;
effektText.text = " " + effekt2;
thatImage.sprite = thisSprite;
// Elements
if(thisCard[0].element=="Fire")
{
frame.GetComponent<Image>().color = new Color32(212, 36, 0, 255);
}
if (thisCard[0].element == "Wind")
{
frame.GetComponent<Image>().color = new Color32(43, 255, 245, 255);
}
if (thisCard[0].element == "Earth")
{
frame.GetComponent<Image>().color = new Color32(0, 171, 2, 255);
}
if (thisCard[0].element == "Water")
{
frame.GetComponent<Image>().color = new Color32(13, 82, 125, 255);
}
if (thisCard[0].element == "Light")
{
frame.GetComponent<Image>().color = new Color32(250, 255, 10, 255);
}
if (thisCard[0].element == "Darkness")
{
frame.GetComponent<Image>().color = new Color32(80, 80, 80, 255);
}
//Rarity
if (thisCard[0].seltenheit == "common")
{
rarity.GetComponent<Image>().color = new Color32(232, 0, 255, 255);
}
if (thisCard[0].element == "rare")
{
frame.GetComponent<Image>().color = new Color32(135, 0, 255, 255);
}
if (thisCard[0].element == "legendary")
{
frame.GetComponent<Image>().color = new Color32(255, 160, 0, 255);
}
//Symbols
if (thisCard[0].legendary == true)
{
legendar.SetActive(true);
}
else
{
legendar.SetActive(false);
}
if (thisCard[0].flying == true)
{
fly.SetActive(true);
}
else
{
fly.SetActive(false);
}
if (thisCard[0].range == true)
{
bow.SetActive(true);
}
else
{
bow.SetActive(false);
}
//Card Back
staticCardBack = cardBack;
if(this.tag == "Clone")
{
thisCard[0] = PlayerDeck.staticDeck[numberOfCardsInDeck - 1];
numberOfCardsInDeck -= 1;
PlayerDeck.deckSize -= 1;
cardBack = false;
this.tag = "Untagged";
}
}
}
thanks in advance and sorry for the spelling errors