// Use this for initialization void Start() { spawntimeE = 5 + Random.Range(0, 10); spawntimeM = 3 + Random.Range(0, 5); spawntimeH = 2 + Random.Range(0, 3); Penguin = GameObject.Find("Penguin"); penguinData = Penguin.GetComponent <PenguinData>(); Directory = Penguin.GetComponent <PenguinDirectory>(); timer = 0; }
// Use this for initialization void Start() { // spawntimeE = 5 + Random.Range(0, 10); // spawntimeM = 3 + Random.Range(0, 5); // spawntimeH = 2 + Random.Range(0, 3); Penguin = GameObject.Find("Penguin"); penguinData = Penguin.GetComponent <PenguinData>(); Directory = Penguin.GetComponent <PenguinDirectory>(); penguinMovementController = GameObject.Find("PenguinMovement").GetComponent <PenguinMovementController> (); spawnTimeMin = Directory.SpawnTimeMin; timer = Random.Range(10, spawnTimeMin); spawnTimeMax = Directory.SpawnTimeMax; }
void doMovement() { //Movement keys //Debug.Log(gameObject.transform.eulerAngles.z); if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) || Input.GetAxis("AxisX") >= .1f || Input.GetAxis("AxisX") <= -.1f)//a catch that isnt filled down below. WHile a key is pressed it increments movementheldtimer { movementHeldTimer += Time.deltaTime; constantTransitionTimer += Time.deltaTime; } #region SnapMovement if (isSnapMovement) { if (movementHeldTimer >= 0 && movementHeldTimer < movementHeldTimerValue) { if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetAxis("AxisX") >= .1f) { if (!is360 && (gameObject.transform.eulerAngles.z > 334 || gameObject.transform.eulerAngles.z < 26)) { curRotation -= (Time.deltaTime * dodgeSpeed); if (curRotation < -26 || curRotation > 26) { curRotation = -24.9f; } //Debug.Log("curRotation = " + curRotation); updateRotation(curRotation); } else if (is360) { curRotation -= 36; //curRotation -= (Time.deltaTime * dodgeSpeed); if (curRotation < 0) { curRotation += 360; } updateRotation(curRotation); } } if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow) || Input.GetAxis("AxisX") <= -.1f) { if (!is360 && (gameObject.transform.eulerAngles.z > 334 || gameObject.transform.eulerAngles.z < 26)) { curRotation += (Time.deltaTime * dodgeSpeed); if (curRotation < -26 || curRotation > 26) { curRotation = 24.9f; } updateRotation(curRotation); } else if (is360) { curRotation += 36; //curRotation += (Time.deltaTime * dodgeSpeed); if (curRotation > 360) { curRotation -= 360; } updateRotation(curRotation); } } } else if (movementHeldTimer >= movementHeldTimerValue) { if ((Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) || Input.GetAxis("AxisX") >= .1f && constantTransitionTimer > constantTransitionTimerValue) { if (!is360 && (gameObject.transform.eulerAngles.z > 334 || gameObject.transform.eulerAngles.z < 26)) { curRotation -= (Time.deltaTime * dodgeSpeed); if (curRotation < -26 || curRotation > 26) { curRotation = -24.9f; } //Debug.Log("curRotation = " + curRotation); updateRotation(curRotation); } else if (is360) { curRotation -= 36; //curRotation -= (Time.deltaTime * dodgeSpeed); if (curRotation < 0) { curRotation += 360; } updateRotation(curRotation); } constantTransitionTimer = 0; } if ((Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) || Input.GetAxis("AxisX") <= -.1f) && constantTransitionTimer > constantTransitionTimerValue) { if (!is360 && (gameObject.transform.eulerAngles.z > 334 || gameObject.transform.eulerAngles.z < 26)) { curRotation += (Time.deltaTime * dodgeSpeed); if (curRotation < -26 || curRotation > 26) { curRotation = 24.9f; } updateRotation(curRotation); } else if (is360) { curRotation += 36; //curRotation += (Time.deltaTime * dodgeSpeed); if (curRotation > 360) { curRotation -= 360; } updateRotation(curRotation); } constantTransitionTimer = 0; } } } #endregion #region notSnapMovement if (!isSnapMovement) { if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow) || Input.GetAxis("AxisX") >= .1f) { if (is360)//needs to be not an 'else if' only an if by itself - John { curRotation -= (Time.deltaTime * dodgeSpeed); if (curRotation < 0) { curRotation += 360; } updateRotation(curRotation); } } else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow) || Input.GetAxis("AxisX") <= -.1f) { if (is360)//needs to be not an 'else if' only an if by itself - John { curRotation += (Time.deltaTime * dodgeSpeed); if (curRotation > 360) { curRotation -= 360; } updateRotation(curRotation); } } } #endregion if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D) && !Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.RightArrow)) { movementHeldTimer = 0; constantTransitionTimer = 0; if (!isSnapMovement && doCentering) { centerPlayer(); } } /* * if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow) || Input.GetAxis("AxisY") >= .1f) // speed increase * { * // emissionRate += Time.deltaTime; // If the W key is being pressed, increase * speedMod = 5f; * } * if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow) || Input.GetAxis("AxisY") <= -.1f) // speed Decrease * { * speedMod = .5f; * } */ // end accel and brake system PenguinData penguinData = GameObject.Find("Penguin").GetComponent <PenguinData>(); // DifficultySpawner difficultySpawner = GameObject.Find("SpawnerEasy").GetComponent<DifficultySpawner>(); PenguinDirectory penguinDirectory = GameObject.Find("Penguin").GetComponent <PenguinDirectory>(); // movementSpeed = speedMod + (penguinData.difficultyIndex * (penguinData.score + penguinDirectory.SpawnTimeMin)) / penguinData.score; }