void CreateListDots() { canShoot = false; DotsBottom = new List <DotManager>(); DotsTop = new List <DotManager>(); if (sizeDot == 0) { DotManager dm = InstantiateDot(); sizeDot = dm.DotSprite.bounds.size.x; } float numberBOTTOM = numberDotsToCreate * rationNombreDotsToCreatBottom; for (int i = 0; i < numberBOTTOM; i++) { DotManager dm = InstantiateDot(); dm.GetComponent <Collider2D>().enabled = false; dm.transform.position = getDotPositionBottom(i); DotsBottom.Add(dm); } float numberTOP = numberDotsToCreate * rationNombreDotsToCreatTop; for (int i = 0; i < numberTOP; i++) { DotManager dm = InstantiateDot(); dm.GetComponent <Collider2D>().enabled = false; dm.transform.position = getDotPositionTop(i); DotsTop.Add(dm); } }
void Update() { if (Input.GetMouseButtonDown(0) && !isGameOver && canShoot) { if (DotsTop.Count > 0 || DotsBottom.Count > 0) { DotManager dTOP = null; DotManager dBOTTOM = null; if (DotsTop.Count > 0) { dTOP = DotsTop [0]; } if (DotsBottom.Count > 0) { dBOTTOM = DotsBottom [0]; } StartCoroutine(ShootDot(dBOTTOM, dTOP)); } } }
void CreateDotOnCircle() { Time.timeScale = 1; GameObject prefab = this.DotPrefab; Quaternion rot = prefab.transform.rotation; Vector3 posTOP = new Vector3(0, positionTouchBorderTOP, 0); Transform parentTOP = CircleBorderTOP; float numberTOP = numberDotsOnCircle * ratioNombreDotsOnCircleTop; for (int i = 0; i < (int)numberTOP; i++) { CircleTOP.rotation = Quaternion.Euler(new Vector3(0, 0, i * 360f / (int)numberTOP)); DotManager dm = InstantiateDot(posTOP, rot, parentTOP); dm.ActivateLine(dm.transform.position, dm.transform.parent); } Vector3 posBOTTOM = new Vector3(0, positionTouchBorderBOTTOM, 0); float numberBOTTOM = numberDotsOnCircle * ratioNombreDotsOnCircleBottom; for (int i = 0; i < (int)numberBOTTOM; i++) { CircleBOTTOM.rotation = Quaternion.Euler(new Vector3(0, 0, i * 360f / (int)numberBOTTOM)); DotManager dm = InstantiateDot(posBOTTOM, rot, CircleBorderBOTTOM); dm.ActivateLine(dm.transform.position, dm.transform.parent); } }
IEnumerator ShootDot(DotManager dBottom, DotManager dTop) { canShoot = false; lastShootTop = null; lastShootBottom = null; StopCoroutine("PositioningDots"); StopCoroutine("MoveStartPositionDot"); if (dBottom != null) { dBottom.GetComponent <Collider2D>().enabled = true; dBottom.GetComponent <Collider2D>().isTrigger = true; } if (dTop != null) { dTop.GetComponent <Collider2D>().enabled = true; dTop.GetComponent <Collider2D>().isTrigger = true; } for (int i = 0; i < DotsTop.Count; i++) { DotsTop [i].transform.localScale = Vector3.one; DotsTop [i].transform.position = getDotPositionTop(i); } for (int i = 0; i < DotsBottom.Count; i++) { DotsBottom [i].transform.localScale = Vector3.one; DotsBottom [i].transform.position = getDotPositionBottom(i); } yield return(null); if (DotsBottom.Count != 0 || DotsTop.Count != 0) { PlaySoundShoot(); if (dBottom != null) { DotsBottom.Remove(dBottom); lastShootBottom = dBottom; } if (dTop != null) { DotsTop.Remove(dTop); lastShootTop = dTop; } StartCoroutine(PositioningDots()); Vector3 targetBttom = new Vector3(0, positionTouchBorderBOTTOM, 0); Vector3 targetTop = new Vector3(0, positionTouchBorderTOP, 0); if (dBottom != null) { dBottom.transform.position = getDotPositionBottom(0); //new Vector3 (0, -sizeDot*0.7f, 0); } if (dTop != null) { dTop.transform.position = getDotPositionTop(0); //new Vector3 (0, sizeDot*0.7f, 0); } while (true) { float step = speed * Time.deltaTime; if (dBottom != null) { dBottom.transform.position = Vector3.MoveTowards(dBottom.transform.position, targetBttom, step); } if (dTop != null) { dTop.transform.position = Vector3.MoveTowards(dTop.transform.position, targetTop, step); } if (dBottom != null) { if (dBottom.transform.position == targetBttom || isGameOver) { canShoot = true; break; } } else { if (dTop.transform.position == targetTop || isGameOver) { canShoot = true; break; } } yield return(new WaitForEndOfFrame()); } if (dBottom != null) { dBottom.ActivateLine(targetBttom, CircleBorderBOTTOM); } if (dTop != null) { dTop.ActivateLine(targetTop, CircleBorderTOP); } yield return(new WaitForSeconds(0.001f)); if (DotsBottom.Count == 0 && DotsTop.Count == 0 && !isGameOver) { success = true; } if (success && !isGameOver) { LevelCleared(); } for (int i = 0; i < DotsTop.Count; i++) { DotsTop [i].transform.localScale = Vector3.one; DotsTop [i].transform.position = getDotPositionTop(i); } for (int i = 0; i < DotsBottom.Count; i++) { DotsBottom [i].transform.localScale = Vector3.one; DotsBottom [i].transform.position = getDotPositionBottom(i); } } }