Hey all so I am trying to make a bubble shooter type of game with a few twists - instead of comparing colour i want to check the cluster if theey have the same number just for some context. When the ball collides witht the wall it calls this Coroutine to see what two balls are currently closest to it and looks to see if it can form a pair.
The problem i get is int otherBubbleNumber = bc.ballNumber throws a null, here is the error message :
NullReferenceException: Object reference not set to an instance of an object
BubbleController+d__20.MoveNext () (at Assets/Scripts/Bubble/BubbleController.cs:85)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at /Users/builduser/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:17)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
BubbleController:OnCollisionEnter2D(Collision2D) (at Assets/Scripts/Bubble/BubbleController.cs:66)
If anyone can poitn out what im doing wrong that would be great or if i should look at another way to do this any help would be great - sorry if the code is messy this is supposed to be a quick game xD
IEnumerator CheckImpact(GameObject go){
transform.rotation = Quaternion.identity;
Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, radius, checkLayer);
for (int i = 0; i < hitColliders.Length; i++)
{
//int myNum = ballNumber;
BubbleController bc = hitColliders[i].gameObject.GetComponent<BubbleController>();
int otherBubbleNumber = bc.ballNumber;
if(otherBubbleNumber == ballNumber && bc != this){
if(mergeBubbles.Contains(bc) == false){
mergeBubbles.Add(bc);
}
break;
}
yield return null;
}
yield return new WaitForSeconds(.1f);
if(mergeBubbles.Count != 0){
mergeBubbles.Add(this);
//StartCoroutine(Merge(go));
Debug.Log("POPPED!!");
}else{
StartCoroutine(Stick(go));
Debug.Log("STUCK!!!");
}
yield return null;
}
[ICODE][/ICODE]