IEnumerator DisplayReplace(Transform disp) { Vector3 oldPos = disp.position; yield return(new WaitForSeconds(0.3f)); StartCoroutine(Fading.FadeSprite(1f, 0f, 0.15f, disp.GetComponent <SpriteRenderer>())); while (!UniMath.ApproximatelyEqual(disp.position.x, 5.5f, 0.1f)) { disp.Translate(Vector3.right * 0.1f, Space.World); yield return(new WaitForFixedUpdate()); } yield return(new WaitUntil(() => GridGenerator.checkGrid == false)); //this will execute only when all electrons will have died disp.GetComponent <SpriteRenderer>().color = Color.white; disp.GetComponent <SpriteRenderer>().sprite = displayOff; float curvel = 0f; while (!UniMath.ApproximatelyEqual(disp.position.x, 4.5f, 0.001f)) { disp.position = new Vector3(Mathf.SmoothDamp(disp.position.x, oldPos.x, ref curvel, 0.2f), disp.position.y); yield return(new WaitForFixedUpdate()); } }
public void FadeButton(SpriteRenderer r) { StartCoroutine(Fading.FadeSprite(1f, 0f, 0.1f, r)); }
public void CheckForCurcuit(Vector3 lastPt) { bool pathWasFound = false; for (int i = 0; i < elements.Length; i++) //for every element in level { if (elements[i].GetInstanceID() != this.GetInstanceID() && elementCanBeUsed[i]) //if this element wasn't used and it is not the same element that has this script { for (int j = 0; j < elements[i].connectionsPts.Length; j++) //we need to check all connection points of that element { for (int k = 0; k < connectionsPts.Length; k++) //and compare with points of element that has this script { if (UniMath.ApproximatelyEqual(elements[i].connectionsPts[j], connectionsPts[k], 0.1f)) //float equality { if (!UniMath.ApproximatelyEqual(lastPt, connectionsPts[k], 0.1f)) //check if we're not "going backwards" to the same point that we found before { if (elements[i].isDisplay) //if it is a display, turn it on { elements[i].GetComponent <SpriteRenderer>().sprite = displayOn; ui.displaysRemain--; ui.AddComboDisplay(); StartCoroutine(DisplayReplace(elements[i].transform)); StartCoroutine(elements[i].MoveElectron(lastPt, elements[i].connectionsPts[j], null, this.transform.position)); pathWasFound = true; } else if (elements[i].isPower) { elements[i].GetComponent <SpriteRenderer>().sprite = powerOn; StartCoroutine(elements[i].PowersourcesCooldown()); StartCoroutine(elements[i].MoveElectron(lastPt, elements[i].connectionsPts[j], null, this.transform.position)); pathWasFound = true; } else //continue search { elementCanBeUsed[i] = false; //we can't use founded element no more (to prevent short curcuits (and stack overflows :D)) StartCoroutine(elements[i].MoveElectron(lastPt, elements[i].connectionsPts[j], elements[i], this.transform.position)); if (!elements[i].isPower) { StartCoroutine(Fading.FadeSprite(1f, 0f, 0.15f, elements[i].GetComponent <SpriteRenderer>(), 0.5f, false)); GridGenerator.grid[(int)Mathf.Round(elements[i].transform.position.x + 2.5f), (int)Mathf.Round(elements[i].transform.position.y + 4f)] = null; } pathWasFound = true; } } } } } } } if (!pathWasFound) { if (UniMath.ApproximatelyEqual(lastPt, connectionsPts[0])) { StartCoroutine(MoveElectron(lastPt, connectionsPts[1], null, this.transform.position)); } else { StartCoroutine(MoveElectron(lastPt, connectionsPts[0], null, this.transform.position)); } } }