I am trying to slow down time in my game but upon using timescale I find that I cannot make the player move normally. Is there any way to exclude the player from the slow motion?
code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovment : MonoBehaviour {
public float moveSpeed;
public float jumpHeight;
public bool timeSlowed;
// Use this for initialization
void Start () {
timeSlowed = false;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.W))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
if (Input.GetKey(KeyCode.A))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if (Input.GetKey(KeyCode.D))
{
GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
if (Input.GetKey(KeyCode.Space ) && !timeSlowed)
{
Time.timeScale = 0.5f;
Time.fixedDeltaTime = 0.02F * Time.timeScale;
moveSpeed = moveSpeed * 2;
jumpHeight = jumpHeight / 2;
timeSlowed = true;
}
}
}