Hi everyone,
I have this script where when you press Space, that slows down time (bullet time). The thing is that I want the speed of the character increased a little bit when the time slows down, but when I press Space it gives me this error:
‘Object reference not set to an instance of an object’ (and the character slows down like everything else in the scene).
Does the problem come from the bullet time?
And is it possible or easier to slow down every objects in the scene but the player instead?
Here’s the script:
var currentBulletTimer : float = 0;
var bulletTimeAllowed : float = 30.0;
//private var speed : float = 0;
private var speed : int = 0;
//variable to access the C# script
private var csScript : Controller2D;
function Awake()
{
//Get the CSharp Script
csScript = this.GetComponent("Controller2D");
}
function Update ()
{
if (Input.GetKeyDown(KeyCode.Space)) {
//if (Input.GetButtonDown ("Fire2")) {
if (Time.timeScale == 1.0)
Time.timeScale = 0.3;
else
Time.timeScale = 1.0;
//Time.fixedDeltaTime = 0.02 * Time.timeScale;
}
if (Time.timeScale == 0.3)
{
currentBulletTimer += Time.deltaTime;
//increase speed
speed = Controller2D.walkSpeed = 30;
}
if ( currentBulletTimer > bulletTimeAllowed )
{
currentBulletTimer = 0;
Time.timeScale = 1.0;
}
}
(The problem doesn’t come from the Controller2D C# script since I put it in the Standard Assets folder.)
Thanks for any help I can get!