Null reference exception instatiante?
this is a weird one,i keep failing at this,i keep using my prefab as a gameobject because otherwise it cant be found,the prefab is "found" and set,but on the clone part it give the error NullreferenceException using UnityEngine; using UnityEngine.UI; using System.Collections; using System.Collections.Generic;
public class Deck : MonoBehaviour { public GameObject ImageClone; public Transform Cparent; List Cardname = new List (); List cardnum = new List (); public void dek () { Cardname.Add ("card Attack"); Cardname.Add ("card Attack(1)"); Cardname.Add ("card Defence"); Cardname.Add ("card Defence(1)"); cardnum.Add (0); cardnum.Add (1); cardnum.Add (2); cardnum.Add (3); } public void randomise () { ImageClone = GameObject.FindWithTag ("prefab"); Debug.Log (ImageClone); if (Cardname.Count != 0) { int Randomstringnum = cardnum [Random.Range (0, (cardnum.Count - 1))]; string RandomString = Cardname [Randomstringnum]; GameObject anyObjectWhichShouldBeTheParentOfThisOne = GameObject.FindWithTag ("ruka(1)"); Cparent = anyObjectWhichShouldBeTheParentOfThisOne.transform; GameObject card = Instantiate (ImageClone, transform.position, Quaternion.identity) as GameObject; /GameObject card = GameObject.FindWithTag (RandomString);/ card.gameObject.transform.localScale -= new Vector3 (0.5116665307471844f, 0.5116665307471844f, 0); card.transform.SetParent (Cparent); Cardname.Remove (RandomString); cardnum.Remove (Randomstringnum); if (Cardname.Count == 0) { GameObject brisi = GameObject.FindWithTag ("Deck"); Destroy (brisi); } } }
}
Your answer
Follow this Question
Related Questions
Workflow ideas needed 0 Answers
How to Change the Variables of an Instantiated Object? 0 Answers