// B I G thanks to ForestJohsson on the Unity IRC.
var crosshairTexture : Texture2D;
var weaponSelect : Texture2D;
var position : Rect;
var position_Select : Rect;
var bulletTime = false;
var targetTimeScale = 2.0;
var targetPitch = 0.5;
var fadeSpeed = 1.0;
var playerSpeed = 1.0;
var normalAudio:GameObject;
var bulletTimeAudio:GameObject;
function Start ()
{
position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
position_Select = Rect( ( Screen.width - weaponSelect.width ) / 2, ( Screen.height - weaponSelect.height ) / 2, weaponSelect.width, weaponSelect.height );
normalAudio = GameObject.Find("normalAudio");
mainAudio = normalAudio.GetComponent("AudioSource");
bulletTimeAudio = GameObject.Find("bulletTimeAudio");
timeAudio = bulletTimeAudio.GetComponent("AudioSource");
}
function OnGUI() // Switch crosshair Texture based on bulletTime
{
if (bulletTime)
{
GUI.DrawTexture( position_Select, weaponSelect );
}
else
{
GUI.DrawTexture( position, crosshairTexture );
}
}
function Update ()
{
// Adjust fixed delta time according to timescale
// The fixed delta time will now be 0.02 frames per real-time second
Time.fixedDeltaTime = 0.02 * Time.timeScale;
normalAudio.audio.pitch = Mathf.Lerp (Time.timeScale, targetPitch, Time.deltaTime * fadeSpeed);
bulletTimeAudio.audio.pitch = Mathf.Lerp (Time.timeScale, targetPitch, Time.deltaTime * fadeSpeed);
Time.timeScale = Mathf.Lerp (Time.timeScale, targetTimeScale, Time.deltaTime * fadeSpeed);
renderSettings = Mathf.Lerp (Time.timeScale, targetTimeScale, Time.deltaTime * fadeSpeed);
if (Input.GetButtonDown ("Fire2")) // toggle bullet time on button down
{
if(bulletTime)
{
// bulletTime off.
targetTimeScale = 1.0;
targetPitch = 1;
RenderSettings.ambientLight = new Color (0.2, 0.2, 0.2);
playerSpeed = 2.0;
}
else
{
// bulletTime on.
playerSpeed = 5000.0;
targetTimeScale = 0.08;
targetPitch = 0.9;
RenderSettings.ambientLight = new Color (0.01, 0.01, 0.01);
}
// maintain the status of the bulleTime var, actually toggle it and stuff
bulletTime = !bulletTime;
}
}