- Home /
Question by
Infiniteno · Nov 14, 2014 at 10:56 AM ·
timeslowmotion
Time.timeScale question
Why doesn't this code make it so time plays at 3x speed until I use horizontal input? It simply returns a 3x speed effect constantly. I've tried about 10 different combinations for this so far and I can only get it to work perfectly in reverse. IE time speeds up on horizontal and then returns to normal when input is null.
using UnityEngine;
using System.Collections;
public class FastMo : MonoBehaviour {
void start()
{
Time.timeScale = 3f;
}
void Update()
{
if (Input.GetButtonDown ("Horizontal"))
{
if (Time.timeScale == 3f)
Time.timeScale = 1f;
}
else
{
Time.timeScale = 3f;}
}
}
Comment
Best Answer
Answer by AlwaysSunny · Nov 14, 2014 at 11:00 AM
Horizontal sounds like an axis to me, in which case you'd want GetAxis and check whether it's non-zero.
Time.timeScale = (Input.GetAxis("Horizontal")==0) ? 1 : 3;
WINNER WINNER! Thank you very much for pointing out what I was to silly to notice! `