protected void Start() { // Cache component references _characterController = GetComponent <CharacterController>(); _controllerHeight = _characterController.height; // Get the main camera and cache local position within the FPS rig _camera = Camera.main; _localSpaceCameraPos = _camera.transform.localPosition; // Set initial to not jumping and not moving _movementStatus = PlayerMoveStatus.NotMoving; // Reset timers _fallingTimer = 0.0f; // Setup Mouse Look Script _mouseLook.Init(transform, _camera.transform); // Initiate Head Bob Object _headBob.Initialize(); _headBob.RegisterEventCallback(1.5f, PlayFootStepSound, CurveControlledBobCallbackType.Vertical); if (_flashLight) { _flashLight.SetActive(false); } }
// Update is called once per frame void Update() { // in case of character falling, increase the fallingTimer if (_characterController.isGrounded) { _fallingTimer = 0f; } else { _fallingTimer += Time.deltaTime; } // Allow Mouse Look a chance to process mouse and rotate camera if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } // Validate Jump button, and we read it from here to not miss it in other update function if (!_jumpButtonPressed) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { // TODO: Play Landing sound or calculate damage } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = _characterController.isGrounded; // Cursor release if (Input.GetKey(KeyCode.Escape)) { Cursor.lockState = CursorLockMode.None; } }
protected void Update() { // If we are falling increment timer if (_characterController.isGrounded) { _fallingTimer = 0.0f; } else { _fallingTimer += Time.deltaTime; } // Allow Mouse Look a chance to process mouse and rotate camera if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } // Process the Jump Button // the jump state needs to read here to make sure it is not missed if (!_jumpButtonPressed) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } // Calculate Character Status if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { // TODO: Play Landing Sound } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = _characterController.isGrounded; }
void RUN() { status = PlayerMoveStatus.Run; if (_SA != null) { _SA.Run_Play(); } }
void Run() { status = PlayerMoveStatus.Run; if (p_Animation != null) { p_Animation.Run_Play(); } }
protected void Update() { if (_characterController.isGrounded) { _fallingTimer = 0.0f; } else { _fallingTimer += Time.deltaTime; } //helps mouselook have time to process mouse and rotate camera if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } if (!_jumpButtonPressed) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } //calculating character status if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { //sound } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = _characterController.isGrounded; }
protected void Start() { _characterController = GetComponent <CharacterController>(); _camera = Camera.main; //look for tag Main Camera _movementStatus = PlayerMoveStatus.NotMoving; _fallingTimer = 0.0f; _mouseLook.Init(transform, _camera.transform); }
void DOUBLEJUMP() { status = PlayerMoveStatus.DoubleJump; rigidbody.AddForce (0, Jump_Power, 0); //더블 점프 애니메이션을 재생한다. if (_SA != null) _SA.D_Jump_Play (); //점프하는 소리를 재생한다. if (_SP != null) _SP.SoundPlay (0); }
void JUMP() { status = PlayerMoveStatus.Jump; rigidbody.AddForce (0, Jump_Power * 1.5f, 0); //점프 애니메이션을 재생한다. if (_SA != null) _SA.Jump_Play (); //점프하는 소리를 재생한다. if (_SP != null) _SP.SoundPlay (0); }
// Use this for initialization void Start() { // Initial state of the pointer Cursor.lockState = CursorLockMode.Locked; _characterController = GetComponent <CharacterController>(); _camera = Camera.main; // Initialization of some variables _movementStatus = PlayerMoveStatus.NotMoving; _fallingTimer = 0f; // Mouse Look Initialization _mouseLook.Init(transform, _camera.transform); }
void DoubleJump() { status = PlayerMoveStatus.DoubleJump; GetComponent <Rigidbody>().AddForce(0, Jump_Power, 0); if (p_Animation != null) { p_Animation.Double_Jump_Play(); } if (p_Sound != null) { p_Sound.SoundPlay(0); } }
void DOUBLEJUMP() { status = PlayerMoveStatus.DoubleJump; GetComponent <Rigidbody>().AddForce(0, Jump_Power, 0); //?붾툝 ?먰봽 ?좊땲硫붿씠?섏쓣 ?ъ깮?쒕떎. if (_SA != null) { _SA.D_Jump_Play(); } //?먰봽?섎뒗 ?뚮━瑜??ъ깮?쒕떎. if (_SP != null) { _SP.SoundPlay(0); } }
protected void Start() { // Cache component references _characterController = GetComponent <CharacterController> (); // Get the main camera and cache local position within the FPS rig _camera = Camera.main; // Set initial to not jumping and not moving _movementStatus = PlayerMoveStatus.NotMoving; // Reset timers _fallingTimer = 0.0f; // Setup Mouse Look Script _mouseLook.Init(transform, _camera.transform); }
void DOUBLEJUMP() { status = PlayerMoveStatus.DoubleJump; rigidbody.AddForce(0, Jump_Power, 0); //더블 점프 애니메이션을 재생한다. if (_SA != null) { _SA.D_Jump_Play(); } //점프하는 소리를 재생한다. if (_SP != null) { _SP.SoundPlay(0); } }
protected void Start() { _characterController = GetComponent <CharacterController>(); _controllerHeight = _characterController.height; _camera = Camera.main; _localSpaceCameraPos = _camera.transform.localPosition; _movementStatus = PlayerMoveStatus.NotMoving; _fallingTimer = 0.0f; //初始化MouseLook脚本 _mouseLook.Init(transform, _camera.transform); _headBob.Initialize(); _headBob.RegisterEventCallback(1.5f, PlayFootStepSound, CurveControlledBobCallbackType.Vertical); if (_flashLight) { _flashLight.SetActive(false); } }
void JUMP() { status = PlayerMoveStatus.Jump; GetComponent <Rigidbody>().AddForce(0, Jump_Power * 1.5f, 0); //?먰봽 ?좊땲硫붿씠?섏쓣 ?ъ깮?쒕떎. if (_SA != null) { _SA.Jump_Play(); } //?먰봽?섎뒗 ?뚮━瑜??ъ깮?쒕떎. if (_SP != null) { _SP.SoundPlay(0); } }
void JUMP() { status = PlayerMoveStatus.Jump; rigidbody.AddForce(0, Jump_Power * 1.5f, 0); //점프 애니메이션을 재생한다. if (_SA != null) { _SA.Jump_Play(); } //점프하는 소리를 재생한다. if (_SP != null) { _SP.SoundPlay(0); } }
protected void Start() { characterController = GetComponent <CharacterController>(); _controllerHeight = characterController.height; _camera = Camera.main; _localSpaceCameraPos = _camera.transform.localPosition; _movementStatus = PlayerMoveStatus.NotMoving; _fallingTimer = 0; _mouseLook.Init(transform, _camera.transform); _headBob.Initialize(); if (_flashLight) { _flashLight.SetActive(false); } }
protected void Start() { // component references characterController = GetComponent <CharacterController>(); controllerHeight = characterController.height; // Get the main camera and save its local position within the FPS rig _camera = Camera.main; localSpaceCameraPos = _camera.transform.localPosition; //every frame can generate offset frm this vector, so now rounding errors // Set movementStatus to not jumping and not moving movementStatus = PlayerMoveStatus.NotMoving; // Reset timers fallingTimer = 0.0f; // Setup Mouse Look Script. Uses MouseLook script thats already available. mouseLook.Init(transform, _camera.transform); // Initiate Head Bob Object headBob.Initialize(); //Plays footstep sound when YplayHead passes the 1.5 second mark headBob.RegisterEventCallback(1.5f, PlayFootStepSound, CurveControlledBobCallbackType.Vertical); //Make sure the game starts wuth flashlight set to inactive if (flashLight) { flashLight.SetActive(false); } //All sprites in inventory set to inactive m4Sprite.enabled = false; shotgunSprite.enabled = false; keySprite.enabled = false; endKeySprite.enabled = false; }
//functions protected void Start() { _characterController = GetComponent <CharacterController>(); _controllerHeight = _characterController.height; //searches for camera with main camera tag _camera = Camera.main; _localSpaceCameraPos = _camera.transform.localPosition; print(_localSpaceCameraPos); _movementStatus = PlayerMoveStatus.NOTMOVING; _fallingTimer = 0.0f; _mouseLook.Init(transform, _camera.transform); _headBob.Initialize(); _headBob.RegisterEventCallback(1.5f, PlayFootstepSound, CurveControlledBobCallbackType.VERTICAL); if (_flashLight) { _flashLight.SetActive(false); } }
protected void Update() { //falling increment timer if (_characterController.isGrounded) { _fallingTimer = 0.0f; } else { _fallingTimer += Time.deltaTime; } //allow time for mouse movement, game isnt paused if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } //flashlight if (Input.GetButtonDown("Flashlight")) { if (_flashLight) { _flashLight.SetActive(!_flashLight.activeSelf); } } //jump if (!_jumpButtonPressed && !_isCrouching) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } //Crouching if (Input.GetButtonDown("Crouch")) { _isCrouching = !_isCrouching; _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight; } //jump status if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { //TODO play landing sound } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.LANDING; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NOTGROUNDED; } else if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NOTMOVING; } else if (_isCrouching) { _movementStatus = PlayerMoveStatus.CROUCHING; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.WALKING; } else { _movementStatus = PlayerMoveStatus.RUNNING; } _previouslyGrounded = _characterController.isGrounded; }
void Update() { if (_characterController.isGrounded) { _fallingTimer = 0f; } else { _fallingTimer += Time.deltaTime; } // If the game is not paused if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } if (Input.GetButtonDown("Flashlight")) { if (_flashLight) { _flashLight.SetActive(!_flashLight.activeSelf); } } if (!_jumpButtonPressed && !_isCrouching) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } if (_characterController.isGrounded && Input.GetButtonDown("Crouch")) { _isCrouching = !_isCrouching; _characterController.height = _isCrouching ? _characterControllerHeight / 2f : _characterControllerHeight; } if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 5f) { // TODO: Landing soud effect _fallingTimer = 0f; } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (_characterController.velocity.sqrMagnitude < .01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isCrouching) { _movementStatus = PlayerMoveStatus.Crouching; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = _characterController.isGrounded; if (_movementStatus == PlayerMoveStatus.Running) { _stamina.value = Mathf.Max(0f, _stamina.value - _staminaDepletion * Time.deltaTime); } else { _stamina.value = Mathf.Min(100, _stamina.value + Time.deltaTime * _staminaRecovery); } _dragMultiplier = Mathf.Min(_dragMultiplierLimit, _dragMultiplier + Time.deltaTime); }
void RUN() { status = PlayerMoveStatus.Run; if (_SA != null) _SA.Run_Play (); }
protected void Update() { //下落计时器,在地面上则为0 if (_characterController.isGrounded) { _fallingTimer = 0.0f; } else { _fallingTimer += Time.deltaTime; } if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } //手电筒触发 if (Input.GetButtonDown("Flashlight")) { if (_flashLight) { _flashLight.SetActive(!_flashLight.activeSelf); } } //跳跃判定,不可在跳跃过程中按跳跃键 if (!_jumpButtonPressed) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } //爬行判定 if (Input.GetButtonDown("Crouch")) { _isCrouching = !_isCrouching; _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight; } //落地时刻 if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { //TODO:落地音效 } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else //空中 if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else //静止 if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else //行走 if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else //跑步 { _movementStatus = PlayerMoveStatus.Runnig; } _previouslyGrounded = _characterController.isGrounded; }
protected void Update() { // Se siamo in caduta fa partire il timer if (_characterController.isGrounded) { _fallingTimer = 0.0f; } else { _fallingTimer += Time.deltaTime; } if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } if (Input.GetButtonDown("Flashlight")) { if (_flashLight) { _flashLight.SetActive(!_flashLight.activeSelf); } } // Lettura pressione pulsante Jump if (!_jumpButtonPressed && !_isCrouching) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } if (Input.GetButtonDown("Crouch")) { _isCrouching = !_isCrouching; _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight; } // Calcola lo Status del Character if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { // TODO: Play Landing Sound } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isCrouching) { _movementStatus = PlayerMoveStatus.Crouching; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = _characterController.isGrounded; _dragMultiplier = Mathf.Min(_dragMultiplier + Time.deltaTime, _dragMultiplierLimit); }
protected void Update() { _fallingTimer += Time.deltaTime; // Allow Mouse Look a chance to process mouse and rotate camera if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } if (Input.GetButtonDown("Flashlight")) { if (_flashLight) { _flashLight.SetActive(!_flashLight.activeSelf); } } if (!_jumpButtonPressed && !_isCrouching) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } if (Input.GetButtonDown("Crouch")) { _isCrouching = !_isCrouching; characterController.height = _isCrouching == true ? _controllerHeight / 2 : _controllerHeight; } if (!_previouslyGrounded && characterController.isGrounded) { if (_fallingTimer > 0.5f) { _fallingTimer = 0.0f; } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isCrouching) { _movementStatus = PlayerMoveStatus.Crouching; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = characterController.isGrounded; }
protected void Update() { if (Time.timeScale != 0) { // If grounded keep falling timer at 0. Else we are falling so increment timer if (characterController.isGrounded) { fallingTimer = 0.0f; } else { fallingTimer += Time.deltaTime; } // First checks if game is paused, if it isnt, then reads horizontal and vertical mouse movement. Either rotates char controller left/right for horizontal mouse movement //or rotate camera up and down for vertical mouse movement. if (Time.timeScale > Mathf.Epsilon) { mouseLook.LookRotation(transform, _camera.transform); } //if player press F, flashlight set to active if (Input.GetButtonDown("Flashlight")) { if (flashLight) { flashLight.SetActive(!flashLight.activeSelf); } } //Jump button pressed then jumpButtonpressed set to true if (!jumpButtonPressed && !isCrouching) { jumpButtonPressed = Input.GetButtonDown("Jump"); } //character controller height is halved when crouch button pressed if (Input.GetButtonDown("Crouch")) { isCrouching = !isCrouching; if (isCrouching == true) { characterController.height = controllerHeight / 2.0f; } else { characterController.height = controllerHeight; } } // Calculates Character Status if (!previouslyGrounded && characterController.isGrounded) { moveDirection.y = 0f; isJumping = false; movementStatus = PlayerMoveStatus.Landing; } else if (!characterController.isGrounded) { movementStatus = PlayerMoveStatus.NotGrounded; } else if (characterController.velocity.sqrMagnitude < 0.01f) { movementStatus = PlayerMoveStatus.NotMoving; } else if (isCrouching) { movementStatus = PlayerMoveStatus.Crouching; } else if (isWalking) { movementStatus = PlayerMoveStatus.Walking; } else { movementStatus = PlayerMoveStatus.Running; } previouslyGrounded = characterController.isGrounded; } }
protected void Update() { // If we are falling increment timer if (_characterController.isGrounded) { _fallingTimer = 0.0f; } else { _fallingTimer += Time.deltaTime; } // Allow Mouse Look a chance to process mouse and rotate camera if (Time.timeScale > Mathf.Epsilon) { _mouseLook.LookRotation(transform, _camera.transform); } if (Input.GetButtonDown("Flashlight")) { if (_flashLight) { _flashLight.SetActive(!_flashLight.activeSelf); } } // Process the Jump Button // the jump state needs to read here to make sure it is not missed if (!_jumpButtonPressed && !_isCrouching) { _jumpButtonPressed = Input.GetButtonDown("Jump"); } if (Input.GetButtonDown("Crouch")) { _isCrouching = !_isCrouching; _characterController.height = _isCrouching == true ? _controllerHeight / 2.0f : _controllerHeight; } // Calculate Chatacter Status if (!_previouslyGrounded && _characterController.isGrounded) { if (_fallingTimer > 0.5f) { // TODO: Play Landing Sound } _moveDirection.y = 0f; _isJumping = false; _movementStatus = PlayerMoveStatus.Landing; } else if (!_characterController.isGrounded) { _movementStatus = PlayerMoveStatus.NotGrounded; } else if (_characterController.velocity.sqrMagnitude < 0.01f) { _movementStatus = PlayerMoveStatus.NotMoving; } else if (_isCrouching) { _movementStatus = PlayerMoveStatus.Crouching; } else if (_isWalking) { _movementStatus = PlayerMoveStatus.Walking; } else { _movementStatus = PlayerMoveStatus.Running; } _previouslyGrounded = _characterController.isGrounded; // Calculate Stamina if (_movementStatus == PlayerMoveStatus.Running) { _stamina = Mathf.Max(_stamina - _staminaDepletion * Time.deltaTime, 0.0f); } else { _stamina = Mathf.Min(_stamina + _staminaRecovery * Time.deltaTime, 100.0f); } _dragMultiplier = Mathf.Min(_dragMultiplier + Time.deltaTime, _dragMultiplierLimit); }