// Use this for initialization void Start() { cc = this.GetComponent <CharacterController> (); ani = this.GetComponent <AnimateCharacter> (); Debug.Log("starting player-move script..."); }
// Update is called once per frame void Update() { previousX = System.Math.Round(this.gameObject.transform.position.x, 2); if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) { isSprinting = true; } if (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift)) { isSprinting = false; } if (Input.GetKeyDown(KeyCode.Escape)) { pauseMenu.SetActive(true); Time.timeScale = 0f; } // How Objects are thrown if (Input.GetKeyDown(KeyCode.Mouse1) && hasArrows) { if (isFacingLeft == false) { Instantiate(arrow, spawnRight.transform.position, transform.rotation); hasArrows = false; StartCoroutine(fireballDelay()); } else if (isFacingLeft == true) { Instantiate(arrow, spawnLeft.transform.position, transform.rotation); hasArrows = false; StartCoroutine(fireballDelay()); } source.PlayOneShot(fireball); } // Lightning if (Input.GetKeyDown(KeyCode.E) && lightningAbility) { lightning.gameObject.SetActive(true); lightningAbility = false; StartCoroutine(lightningDelay()); source.PlayOneShot(lightningSound); } // Bubble Shield if (Input.GetKeyDown(KeyCode.Q) && bubbleAbility) { bubbleShield.gameObject.SetActive(true); bubbleAbility = false; StartCoroutine(shieldLifeDelay(bubbleLifeSpan)); } // Sword if (Input.GetKeyDown(KeyCode.Mouse0) && !isAttacking && !isMoving) { AnimateCharacter ac = gameObject.GetComponent <AnimateCharacter>(); ac.curSpriteCount = 0; StartCoroutine(Attack(.4f)); source.PlayOneShot(swingSword); } CharacterController controller = GetComponent <CharacterController>(); if (isClimbing) { moveDirection.x = Input.GetAxis("Horizontal"); moveDirection.y = Input.GetAxis("Vertical"); moveDirection *= speed; DBMovement(); } else if (controller.isGrounded) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0); moveDirection = transform.TransformDirection(moveDirection); isJumping = false; DBMovement(); if (isSprinting) { moveDirection *= sprintSpeed; } if (!isSprinting) { moveDirection *= speed; } if (Input.GetButton("Jump") && !isJumping) { moveDirection.y = jumpSpeed; isJumping = true; } moveDirection.y -= gravity * Time.deltaTime; } else { moveDirection.x = Input.GetAxis("Horizontal"); if (isSprinting) { moveDirection.x *= sprintSpeed; } if (!isSprinting) { moveDirection.x *= speed; } DBMovement(); moveDirection.y -= gravity * Time.deltaTime; } controller.Move(moveDirection * Time.deltaTime); currentX = System.Math.Round(this.gameObject.transform.position.x, 2); //Check to see if we are currently moving... this is needed for animation purposes... if (previousX != currentX) { isMoving = true; } else if (previousX == currentX) { isMoving = false; } }