public bool IsCharacterHit(IItem item) { if (_playerState == EnumPlayerState.Invulnerable) { return(false); } if (item.GetOrigin() == _player) { return(false); } _playerState = EnumPlayerState.Hit; if (_item != null) { //when carrying item, remove from player if (_item.GetState() == EnumItemState.PICKED) { Debug.Log("REMOVING ITEM "); _item.RemoveItem(); } _item = null; } return(true); }
void DecideDirectionAndShoot() { if (((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f)) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { velocityVector = Vector3.zero; stateAnimation = EnumPlayerState.STAY; // Parado } else { if ((Input.GetAxis("Horizontal") > 0.1f) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { // Right direction stateAnimation = EnumPlayerState.RIGHT; } if ((Input.GetAxis("Horizontal") < -0.1f) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { // Left direction stateAnimation = EnumPlayerState.LEFT; } if ((Input.GetAxis("Vertical") < -0.1f) && ((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f))) { // Down direction stateAnimation = EnumPlayerState.DOWN; } if ((Input.GetAxis("Vertical") > 0.1f) && ((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f))) { // Up direction stateAnimation = EnumPlayerState.UP; } Vector3 vetorHorizontal = Vector3.right * Mathf.Clamp(velocity * Input.GetAxis("Horizontal"), -velocity, velocity); Vector3 vetorVertical = Vector3.up * Mathf.Clamp(velocity * Input.GetAxis("Vertical"), -velocity, velocity); velocityVector = vetorHorizontal + vetorVertical; } if (Input.GetButtonDown("Fire1") /*&& canShoot && numberShoots > 0*/) { GameObject shootClone = Instantiate(shootPrefab) as GameObject; shootClone.transform.position = transform.position; Vector2 directionShoot = new Vector2(velocityVector.x, velocityVector.y); if (directionShoot.magnitude == 0) { directionShoot = new Vector2(0, -1); } directionShoot.Normalize(); shootClone.rigidbody2D.velocity = directionShoot * ShootVelocity; canShoot = false; numberShoots--; PlayerPrefs.SetInt("PlayerShoots", numberShoots); // play fire effect sound NGUITools.PlaySound(fireSound, 1, 1); } }
void DecideDirectionAndShoot() { if (((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f)) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { velocityVector = Vector3.zero; scriptAnimator.speed = 0; // Parado } else { scriptAnimator.speed = 1; if ((Input.GetAxis("Horizontal") > 0.1f) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { // Right direction stateAnimation = EnumPlayerState.RIGHT; directionShoot = new Vector2(1, 0); } if ((Input.GetAxis("Horizontal") < -0.1f) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { // Left direction stateAnimation = EnumPlayerState.LEFT; directionShoot = new Vector2(-1, 0); } if ((Input.GetAxis("Vertical") < -0.1f) && ((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f))) { // Down direction stateAnimation = EnumPlayerState.DOWN; directionShoot = new Vector2(0, -1); } if ((Input.GetAxis("Vertical") > 0.1f) && ((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f))) { // Up direction stateAnimation = EnumPlayerState.UP; directionShoot = new Vector2(0, 1); } Vector3 vetorHorizontal = Vector3.right * Mathf.Clamp(velocity * Input.GetAxis("Horizontal"), -velocity, velocity); Vector3 vetorVertical = Vector3.up * Mathf.Clamp(velocity * Input.GetAxis("Vertical"), -velocity, velocity); velocityVector = vetorHorizontal + vetorVertical; } if (Input.GetButtonDown("Fire1") && canShoot && numberShoots > 0 && directionShoot != Vector2.zero) { GameObject shootClone = Instantiate(shootPrefab) as GameObject; shootClone.transform.position = transform.position; var rigidbody2D = shootClone.GetComponent <Rigidbody2D>(); rigidbody2D.velocity = directionShoot * ShootVelocity; canShoot = false; numberShoots--; PlayerPrefs.SetInt("PlayerShoots", numberShoots); } }
public void SetStateAnimation(EnumPlayerState state) { stateAnimation = state; }
void UpdateInput() { _verticalAxis = Input.GetAxis("Vertical"); _horizontalAxis = Input.GetAxis("Horizontal"); _horizontalAxisAbsolute = Mathf.Abs(_horizontalAxis); _verticalAxisAbsolute = Mathf.Abs(_verticalAxis); if (_horizontalAxisAbsolute < 0.1f && _verticalAxisAbsolute < 0.1f) { _velocityVector = Vector3.zero; if (_scriptAnimator) _scriptAnimator.speed = 0; } else { if (_scriptAnimator) _scriptAnimator.speed = 1; if (_horizontalAxis >= 0.1f && _verticalAxisAbsolute < 0.4f) { // Right direction _stateAnimation = EnumPlayerState.RIGHT; } if (_horizontalAxis <= -0.1f && _verticalAxisAbsolute < 0.4f) { // Left direction _stateAnimation = EnumPlayerState.LEFT; } if (_horizontalAxis >= 0.1f && _verticalAxis >= 0.4f) { _stateAnimation = EnumPlayerState.RIGHT_UP; } if (_horizontalAxis >= 0.1f && _verticalAxis <= -0.4f) { _stateAnimation = EnumPlayerState.RIGHT_DOWN; } if (_horizontalAxis <= -0.1f && _verticalAxis >= 0.4f) { _stateAnimation = EnumPlayerState.LEFT_UP; } if (_horizontalAxis <= -0.1f && _verticalAxis <= -0.4f) { _stateAnimation = EnumPlayerState.LEFT_DOWN; } if (_verticalAxis <= -0.1f && _horizontalAxisAbsolute < 0.4f) { // Down direction _stateAnimation = EnumPlayerState.DOWN; } if (_verticalAxis >= -0.1f && _horizontalAxisAbsolute < 0.4f) { // Up direction _stateAnimation = EnumPlayerState.UP; } Vector3 vetorHorizontal = Vector3.right * _velocity * _horizontalAxis; Vector3 vetorVertical = Vector3.up * _velocity * _verticalAxis; _velocityVector = Vector3.ClampMagnitude(vetorHorizontal + vetorVertical, _velocity); ; } }
void DecideDirectionAndShoot() { if (((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f)) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { velocityVector = Vector3.zero; scriptAnimator.speed = 0; // Parado } else { scriptAnimator.speed = 1; if ((Input.GetAxis("Horizontal") > 0.1f) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { // Right direction stateAnimation = EnumPlayerState.RIGHT; directionShoot = new Vector2(1, 0); } if ((Input.GetAxis("Horizontal") < -0.1f) && ((Input.GetAxis("Vertical") < 0.1f) && (Input.GetAxis("Vertical") > -0.1f))) { // Left direction stateAnimation = EnumPlayerState.LEFT; directionShoot = new Vector2(-1, 0); } if ((Input.GetAxis("Vertical") < -0.1f) && ((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f))) { // Down direction stateAnimation = EnumPlayerState.DOWN; directionShoot = new Vector2(0, -1); } if ((Input.GetAxis("Vertical") > 0.1f) && ((Input.GetAxis("Horizontal") < 0.1f) && (Input.GetAxis("Horizontal") > -0.1f))) { // Up direction stateAnimation = EnumPlayerState.UP; directionShoot = new Vector2(0, 1); } Vector3 vetorHorizontal = Vector3.right * Mathf.Clamp(velocity * Input.GetAxis("Horizontal"), -velocity, velocity); Vector3 vetorVertical = Vector3.up * Mathf.Clamp(velocity * Input.GetAxis("Vertical"), -velocity, velocity); velocityVector = vetorHorizontal + vetorVertical; } if (Input.GetButtonDown("Fire1") && canShoot && numberShoots > 0 && directionShoot != Vector2.zero) { GameObject shootClone = Instantiate(shootPrefab) as GameObject; shootClone.transform.position = transform.position; shootClone.rigidbody2D.velocity = directionShoot * ShootVelocity; canShoot = false; numberShoots--; PlayerPrefs.SetInt("PlayerShoots", numberShoots); } }
void UpdateInput() { _verticalAxis = Input.GetAxis("Vertical"); _horizontalAxis = Input.GetAxis("Horizontal"); _horizontalAxisAbsolute = Mathf.Abs(_horizontalAxis); _verticalAxisAbsolute = Mathf.Abs(_verticalAxis); if (_horizontalAxisAbsolute < 0.1f && _verticalAxisAbsolute < 0.1f) { _velocityVector = Vector3.zero; if (_scriptAnimator) { _scriptAnimator.speed = 0; } } else { if (_scriptAnimator) { _scriptAnimator.speed = 1; } if (_horizontalAxis >= 0.1f && _verticalAxisAbsolute < 0.4f) { // Right direction _stateAnimation = EnumPlayerState.RIGHT; } if (_horizontalAxis <= -0.1f && _verticalAxisAbsolute < 0.4f) { // Left direction _stateAnimation = EnumPlayerState.LEFT; } if (_horizontalAxis >= 0.1f && _verticalAxis >= 0.4f) { _stateAnimation = EnumPlayerState.RIGHT_UP; } if (_horizontalAxis >= 0.1f && _verticalAxis <= -0.4f) { _stateAnimation = EnumPlayerState.RIGHT_DOWN; } if (_horizontalAxis <= -0.1f && _verticalAxis >= 0.4f) { _stateAnimation = EnumPlayerState.LEFT_UP; } if (_horizontalAxis <= -0.1f && _verticalAxis <= -0.4f) { _stateAnimation = EnumPlayerState.LEFT_DOWN; } if (_verticalAxis <= -0.1f && _horizontalAxisAbsolute < 0.4f) { // Down direction _stateAnimation = EnumPlayerState.DOWN; } if (_verticalAxis >= -0.1f && _horizontalAxisAbsolute < 0.4f) { // Up direction _stateAnimation = EnumPlayerState.UP; } Vector3 vetorHorizontal = Vector3.right * _velocity * _horizontalAxis; Vector3 vetorVertical = Vector3.up * _velocity * _verticalAxis; _velocityVector = Vector3.ClampMagnitude(vetorHorizontal + vetorVertical, _velocity);; } }
// Update is called once per frame void FixedUpdate() { //Apply our top speeds Vector2 vel = rigid.velocity; if (vel.x > lateralTopSpeed) { rigid.velocity = new Vector2(lateralTopSpeed, vel.y); } if (vel.x < -lateralTopSpeed) { rigid.velocity = new Vector2(-lateralTopSpeed, vel.y); } vel = rigid.velocity; if (vel.y > terminalVelocity) { rigid.velocity = new Vector2(vel.x, terminalVelocity); } if (vel.y < -terminalVelocity) { rigid.velocity = new Vector2(vel.x, -terminalVelocity); } //Apply some friction if (Input.GetAxis("Horizontal") == 0 && canJump) { rigid.velocity = new Vector2(vel.x * 0.9f, vel.y); } //Do movement rigid.AddForce(new Vector2(Input.GetAxis("Horizontal") * lateralAcceleration, 0), ForceMode2D.Impulse); //Jump if (Input.GetButtonDown("Jump")) { Jump(); } if (Input.GetButtonDown("Fire1")) { Attack(); } isTouchingGround = Physics2D.Raycast((Vector2)transform.position - groundOffset, -Vector2.up, 0.1f); if (Mathf.Abs(vel.x) == lateralTopSpeed) { state = EnumPlayerState.RUNNING; } else { state = EnumPlayerState.WALKING; } if (!isTouchingGround) { state = EnumPlayerState.FLYING; } switch (state) { case EnumPlayerState.WALKING: range = 1.5f; break; case EnumPlayerState.RUNNING: range = 5f; break; case EnumPlayerState.FLYING: range = 5f; break; } runParticles.SetActive((isTouchingGround && Mathf.Abs(vel.x) + 0.5 > lateralTopSpeed)); }
public void SetState(EnumPlayerState playerState) { _playerState = playerState; }