Hey im sorry that i have to ask a Question again but i really dont understand why my code isnt working
i searched in threads for a solution but nothing seems to work
long story short i want to create a card game and want to disable a script if the card cant be summoned
My error message says
NullReferenceException: Object reference not set to an instance of an object
ThisCard.Update () (at Assets/Scripts/ThisCard.cs:189
as far i understood this error, it doesnt understand what i mean or the object is = null
but it just should get the component and disable or activate it… but see for yourself
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 fliegen;
public GameObject bogen;
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;
public bool canBeSummon;
public bool summoned;
public bool activeTrue;
public GameObject battleZone;
void Start ()
{
thisCard [0] = CardDataBase.cardList[thisId];
numberOfCardsInDeck = PlayerDeck.deckSize;
canBeSummon = false;
summoned = false;
activeTrue = false;
}
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)
{
fliegen.SetActive(true);
}
else
{
fliegen.SetActive(false);
}
if (thisCard[0].range == true)
{
bogen.SetActive(true);
}
else
{
bogen.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";
}
if (activeTrue == false && summoned == false)
{
canBeSummon = true;
}
//else canBeSummon = false;
if (activeTrue == true && TurnSystem.ActivePower >= power)
{
canBeSummon = true;
}
if(canBeSummon == true)
{
this.GetComponent<drag>().enabled = true;
}
else this.GetComponent<drag>().enabled = false;
battleZone = GameObject.Find("ActiveCard");
if(summoned == false && this.transform.parent == battleZone.transform)
{
Summon();
}
}
public void Summon()
{
activeTrue = true;
TurnSystem.ActivePower = power;
summoned = true;
}
}
and this is the drag code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class drag : MonoBehaviour
{
private bool isDragging = false;
private bool isOverDropZone = false;
private GameObject dropZone;
private Vector2 startPosition;
// Update is called once per frame
void Update()
{
if (isDragging)
{
transform.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
isOverDropZone = true;
dropZone = collision.gameObject;
}
private void OnCollisionExit2D(Collision2D collision)
{
isOverDropZone = false;
dropZone = null;
}
public void StartDrag()
{
startPosition = transform.position;
isDragging = true;
}
public void EndDrag()
{
isDragging = false;
if (isOverDropZone)
{
transform.SetParent(dropZone.transform, false);
}
else
{
transform.position = startPosition;
}
}
}
i really hope you can help me understand what im doing wrong and thanks in advance