Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

How can I make this happen one second after this?

$
0
0
I have a script where it measures fall damage and effects the players health when you fall from a certain height and I need to make it so that when you hit the ground(when grounded == true) wait one second and then reset jumpHeight to 0. Here is the script if you need it! using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { //SPEED AND SUCH public float speed = 6.0f; public float strafeSpeed = 5.8f; public float jumpSpeed = 8.0f; public float gravity = 18.125f; public float jumpHeight = 0.0f; private Vector3 moveDirection = Vector3.zero; private bool grounded = false; static public bool isRunning = false; //STAMINA BAR public GUIStyle staminaBar; private float maxStamina = 100.0f; private float curStamina = 100.0f; private float staminaBarLength; void Start () { staminaBarLength = 85; } void Update () { if (grounded) { moveDirection = new Vector3(Input.GetAxis ("Horizontal"),0,Input.GetAxis ("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if(Input.GetKeyDown (KeyCode.LeftShift)) { speed = 10.00f; isRunning = true; } else if(Input.GetKeyUp (KeyCode.LeftShift)) { speed = 6.0f; isRunning = false; } } if (grounded == true) { if(Input.GetKey (KeyCode.Space)) { moveDirection.y = jumpSpeed; } } if (grounded == false) { jumpHeight++; } if (grounded == true && jumpHeight >= 100) { PlayerHealth.curHealth -= 20; } moveDirection.y -= gravity * Time.deltaTime; var Controller = GetComponent (); var flags = Controller.Move (moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0; AdjustCurrentStamina (0); } void OnGUI() { GUI.BeginGroup (new Rect (355, 476, staminaBarLength, 125), string.Empty, staminaBar); GUI.Label (new Rect (16, 7, 45, 110), "Stamina", staminaBar); GUI.EndGroup (); } void AdjustCurrentStamina(int adj) { if (isRunning) { curStamina -= Time.deltaTime * 10.0f; } if (!isRunning) { curStamina += Time.deltaTime * 7.5f; } if (curStamina < 0) { curStamina = 0; } if (curStamina == 0) { speed = 6.0f; if(isRunning == true && curStamina == 0) { speed = 6.0f; } } if (curStamina > maxStamina) { curStamina = maxStamina; } if(maxStamina <1) maxStamina = 1; staminaBarLength =(85) * (curStamina / (float)maxStamina); } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>