public void Respawn() { if (this.respawnState == RespawingState.RespawnFinished) { this.respawnState = RespawingState.StartRespawn; } }
void FixedUpdate() { if (this.isDeath) { RespawingState respawnState = this.gameObject.GetComponent <RespawnScript>().GetState(); if (this.rBody.transform.rotation.eulerAngles.x >= 270f && respawnState == RespawingState.RespawnFinished) { this.gameObject.GetComponent <RespawnScript>().Respawn(); } else if (respawnState == RespawingState.RespawnFinished) { this.respawnText.enabled = true; // make body lying like death const float deathSpeed = 6f; Quaternion deathPosition = Quaternion.Euler(270f, this.rBody.transform.rotation.eulerAngles.y, 0); this.rBody.rotation = Quaternion.Slerp(this.transform.localRotation, deathPosition, Time.deltaTime * deathSpeed); } return; } //this.rBody.AddForce(movement * speed); Vector3 move = this.horizontalMovement + this.verticalMovemnt; this.rBody.velocity = move; float horizontalMouseMove = Input.GetAxis("Mouse X"); float verticalMouseMove = Input.GetAxis("Mouse Y"); this.rBody.rotation = Quaternion.Euler(this.rBody.rotation.eulerAngles + new Vector3(0, horizontalMouseMove * this.mouseSensitive, 0)); // move only camera up-down this.cameraObject.transform.Rotate(new Vector3(verticalMouseMove * this.mouseSensitive * -1, 0, 0)); }
void FixedUpdate() { if (this.respawnState == RespawingState.StartRespawn) { this.currentTime += Time.deltaTime; } if (this.respawnState == RespawingState.Respawning) { this.rBody.AddForce(this.rBody.transform.up * -1, ForceMode.Force); Vector3 currentAngles = this.rBody.transform.rotation.eulerAngles; if (currentAngles.x != 0 || currentAngles.y != 0 || currentAngles.z != 0) { this.transform.rotation = Quaternion.Euler(0, this.rBody.rotation.eulerAngles.y, this.rBody.rotation.eulerAngles.z); } } if (this.currentTime > this.respawnSeconds) { // hide respawn message PlayerController playerController = this.GetComponent <PlayerController>(); playerController.respawnText.enabled = false; this.respawnState = RespawingState.Respawning; this.rBody.transform.position = new Vector3(this.rBody.transform.position.x, this.respawnHeight, this.rBody.transform.position.z); this.currentTime = 0; } if (this.rBody.transform.position.y <= 1 && this.respawnState == RespawingState.Respawning) { this.respawnState = RespawingState.RespawnFinished; this.rBody.useGravity = true; this.rBody.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationX; PlayerController playerController = this.GetComponent <PlayerController>(); playerController.SetAlive(true); playerController.health = 100f; playerController.UpdateHealth(); } }