- Home /
Time.timeScale not working
Hi all I'm having trouble with using Time.timeScale.. not sure if im using it incorrectly.. but im trying to get my game to run at half speed if the collision is detected.. i also tried running it in update.. but neither works :P
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class WinningScript : MonoBehaviour {
private bool Truth = false;
public GameObject Win;
void Start ()
{
Win.GetComponent<Renderer>().enabled = false;
}
void OnTriggerEnter2D (Collider2D coll)
{
if (coll.gameObject.tag == "Player")
{
Truth = true;
Time.timeScale = .5f;
}
}
void Update ()
{
if (Truth == true)
{
Time.timeScale = .5f;
Win.GetComponent<Renderer>().enabled = true;
}
}
}
do you have triggers enabled ? is coll.gameObject.tag really "Player" ?
Answer by taxvi · Jun 22, 2015 at 09:14 AM
I'm not exactly sure how it works but the way I look at it is - it gets multiplied on and assigned to Time.deltaTime before each update call. so if you moved your 'guy' object with speed * Time.deltaTime each frame than the guy will slow down/speed up depending on the timeScale. nothing else gets affected by timeScale.
oh, forgot to mention - Time.fixedDeltaTime gets affected too.