public void setCameraPositionXY() { float xPos = 0; float yPos = 0; GameObject activeRing = activeRings.getActiveRing(); xPos = activeRing.transform.position.x; yPos = activeRing.transform.position.y; StartCoroutine(moveCameraXY(new Vector3(xPos, yPos, transform.position.z))); }
private void OnTriggerEnter(Collider other) { if (other.tag == "Ring") { if (other.gameObject != currentRing) { currentRing = other.gameObject; control.resetExplodeTimer(); } setTriggered(true); control.setMovement(false); control.StopAllCoroutines(); ringToSet = other.transform.parent.gameObject; ringSetToSet = ringToSet.transform.parent.gameObject; transform.parent = other.GetComponentInParent <Transform>(); if (activeRings.getActiveRingSet() != ringSetToSet) { generator.generateRingSet(generator.getNumberOfRings()); } activeRings.setActiveRingSet(ringSetToSet, activeRings.getActiveRingSet()); activeRings.setActiveRing(ringToSet, activeRings.getActiveRing(), control.getHorizontalMove()); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); transform.position = new Vector3(transform.position.x, transform.position.y, other.transform.position.z); currentRow = ringToSet.GetComponent <RingPosition>().getRow(); //set next ring "blinking" to show available = generator.rings.Find(availableRing); control.availableTimer = 0; } if (other.tag == "ChargeGate" && other.GetComponent <Charged>().getChargable()) { StartCoroutine(GetComponent <SparkCharge>().replenishCharge(75)); //replenish 75/100 units of charge other.GetComponent <Charged>().setChargable(false); Destroy(other.gameObject); } }
// Update is called once per frame void Update() { if (trigger.available) { Renderer[] availableRends = trigger.available.GetComponentsInChildren <Renderer>(); if (availableRends.Length > 0) { GameObject availableChild = availableRends[0].gameObject; string availableType = trigger.available.GetComponentInChildren <RingType>().getType(); float previousTime = availableTimer; availableTimer += Time.deltaTime; availableTimer = availableTimer % 0.5f; if (previousTime > availableTimer) { availableIteration++; availableIteration = availableIteration % 2; for (int i = 0; i < availableRends.Length; i++) { if (availableIteration == 0) { availableRends[i].material = activeRings.activeRingSetGlow; } else { availableRends[i].material = activeRings.setRingColour(availableChild); } } } } } if (touchTimerOn && !gameOver) { touchTimer += Time.deltaTime; //for hold move if (touchTimer > 0.3f && direction.y < 25f && direction.y > -25f && !getPaused()) { holdMoved = true; OptionsValues.optionValues.move.Play(); setHorizontalMove(true); StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(sparkMoveHorizontal(spark, spark.transform.localPosition.x)); StartCoroutine(sparkCharge.useCharge(jumpSparkUsed)); touchTimerOn = false; touchTimer = 0; } } /* * //For double tap move * * if (touchDelayTimerOn) * { * touchDelayTimer += Time.deltaTime; * if(touchDelayTimer > 0.3f) * { * OptionsValues.optionValues.move.Play(); * StopAllCoroutines(); * explodeTimer = 4; * trigger.setTriggered(false); * StartCoroutine(sparkJump(spark, spark.GetComponentInParent<Transform>().position.z)); * StartCoroutine(sparkCharge.useCharge(jumpSparkUsed)); * touchDelayTimerOn = false; * touchDelayTimer = 0; * } * } */ if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() == "rotating" && !getPaused() && !touchDelayTimerOn) { if (!holding) { timer += Time.deltaTime; } if (timer >= 1 && !moving) { StartCoroutine(rotateRing(1)); timer = 0; } } else if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() == "timed" && !getPaused()) { timer += Time.deltaTime; explodeTimer -= Time.deltaTime; Renderer[] rends = activeRings.getActiveRing().GetComponentsInChildren <Renderer>(); if (timer >= explodeTimer / 5) { for (int i = 0; i < rends.Length; i++) { if (rends[i].gameObject.tag != "Sphere") { if (iteration % 2 == 0) { rends[i].material = active; } else { rends[i].material = timed; } } } iteration++; timer = 0; } if (explodeTimer <= 0 && !exploded) { exploded = true; gameOver = true; explode(); sparkCharge.endGame(); } } else { timer = 0; explodeTimer = 4; iteration = 0; } if (Input.GetButtonDown("Cancel") && !getPaused()) { GetComponent <Pause>().pause(); setPaused(true); } else if (Input.GetButtonDown("Cancel") && getPaused()) { GetComponent <Pause>().unpause(); setPaused(false); } if (!sparkCharge.getOutOfChargeStatus() && getStarted() && !getPaused() && !gameOver) { if (Input.GetButtonDown("Jump") && !moving) { OptionsValues.optionValues.move.Play(); StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); explodeTimer = 4; trigger.setTriggered(false); StartCoroutine(sparkJump(spark, spark.GetComponentInParent <Transform>().position.z)); StartCoroutine(sparkCharge.useCharge(jumpSparkUsed)); } if (Input.GetButtonDown("moveToNextRing") && !moving) { OptionsValues.optionValues.move.Play(); setHorizontalMove(true); StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(sparkMoveHorizontal(spark, spark.transform.localPosition.x)); StartCoroutine(sparkCharge.useCharge(jumpSparkUsed)); } if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (Input.GetButtonDown("moveRight") && !moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); } if (Input.GetButtonDown("moveLeft") && !moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(-1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); } } else { if (Input.GetButtonDown("moveRight") || Input.GetButtonDown("moveLeft")) { OptionsValues.optionValues.fixedRing.Play(); } } // // // // if (Input.touchCount > 0 && !paused && !gameOver) { Touch touch = Input.GetTouch(0); switch (touch.phase) { case TouchPhase.Began: direction = Vector2.zero; touchStart = touch.position; touchTimerOn = true; setHolding(true); /* * // for double tap move * * if(touchDelayTimer > 0 && touchDelayTimer < 0.3f) * { * doubleTouch = true; * } * else * { * doubleTouch = false; * } */ break; case TouchPhase.Moved: direction = touch.position - touchStart; if (touchStart.x > Screen.width / 2 && !rotateMoved && !getPaused()) { if (direction.y > 25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(-1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); rotateMoved = true; } } } else if (direction.y < -25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); rotateMoved = true; } } } } else if (touchStart.x < Screen.width / 2 && !rotateMoved && !getPaused()) { if (direction.y < -25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(-1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); rotateMoved = true; } } } else if (direction.y > 25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); rotateMoved = true; } } } } break; case TouchPhase.Ended: if (!getPaused() && !holdMoved && !justUnpaused) { direction = touch.position - touchStart; /* * //for double tap move * * if (doubleTouch && !moving) * { * OptionsValues.optionValues.move.Play(); * setHorizontalMove(true); * StopAllCoroutines(); * StartCoroutine(sparkMoveHorizontal(spark, spark.transform.localPosition.x)); * StartCoroutine(sparkCharge.useCharge(jumpSparkUsed)); * touchDelayTimerOn = false; * touchDelayTimer = 0; * } */ if (touchTimer < 0.3f && !moving && direction.y < 25f && direction.y > -25f) { //for hold move OptionsValues.optionValues.move.Play(); StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); trigger.setTriggered(false); StartCoroutine(sparkJump(spark, spark.GetComponentInParent <Transform>().position.z)); StartCoroutine(sparkCharge.useCharge(jumpSparkUsed)); /* * //for double tap move * * touchDelayTimerOn = true; * touchDelayTimer = 0; */ } else if (touchStart.x > Screen.width / 2 && !rotateMoved) { if (direction.y > 25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(-1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); } } } else if (direction.y < -25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); } } } } else if (touchStart.x < Screen.width / 2 && !rotateMoved) { if (direction.y < -25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(-1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); } } } else if (direction.y > 25f) { if (activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "fixed" && activeRings.getActiveRing().GetComponentInChildren <RingType>().getType() != "rotating") { if (!moving) { StopAllCoroutines(); StartCoroutine(mainCamera.setCameraPositionZ()); mainCamera.setCameraPositionXY(); StartCoroutine(rotateRing(1)); StartCoroutine(sparkCharge.useCharge(rotateSparkUsed)); } } } } setHolding(false); touchTimerOn = false; touchTimer = 0; direction = Vector2.zero; } holdMoved = false; rotateMoved = false; justUnpaused = false; break; } } } if (sparkCharge.getOutOfChargeStatus() || gameOver) { gameOver = true; sparkCharge.endGame(); GetComponent <ShowFinalScore>().showFinalScore(); } }