— I Previously Asked A Question About This —
I have my code for my player movement in script and i have been told to have the physics stuff in the update so that when i pause the game, the physics stuff pauses aswell
Here is my code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Movement : MonoBehaviour {
private PauseMenuScript pauseMenuScript;
private Fade myFadeScript;
public float movementSpeed;
public int jumpHeight;
float jumpSpeed;
Vector3 velocity;
void Start(){
pauseMenuScript = GameObject.Find ("Manager").GetComponent<PauseMenuScript> ();
jumpSpeed = Mathf.Sqrt(-2*Physics.gravity.y*jumpHeight) + 0.1f;
}
void FixedUpdate(){
rigidbody.AddRelativeForce(Vector3.right * 10 - rigidbody.velocity);
if(Input.GetKeyDown("up") || (Input.GetMouseButtonDown(0)))
{
velocity = rigidbody.velocity;
velocity.y = jumpSpeed;
rigidbody.velocity = velocity;
}
//if (pauseMenuScript.isPaused)
}
IEnumerator WaitForTime (float waitTime){
yield return new WaitForSeconds (waitTime);
}
}
When the game plays the key press does not always register so the game kinda feels bad, so how would i have it so that this dose not happen in the fixed update.
OR
How could i have it so that in the Update() function, i can reset the veolcity after the game has unpaused
Here is the first thread i posted about this to give you more context:
Thanks