I want to make it so when i collide with my prefab that is tagged “TimeBoost” that it will add a few second to my countdown timer! Posted first is my code that is within my CharMove script (Starts line 50) that is below it. I got the prefab to destroy when my player collides with it but I dont understand why my timer isint gaining any time though? Please help! Thank you!!
{
if(other.gameObject.tag == "TimeBoost")
{
//add time
Timer.timeLeft += 10;
}
private var timeSinceLastCollision = 0;
var timeScale: float = 1;
var character: CharacterController;
var speed: float = 15; // moving speed
var direction: float = 1; // direction (-1 means -x)
var dead = false;
static var hasBoost = false;
var boostSpeed: float = 25;
var defaultSpeed: float = 15;
static var slowGameSpeed = false;
static var slowGameSpeedGUI = false;
static var hasBoostGUI = false;
static var shield = false;
function Start(){
character = transform.GetComponent(CharacterController);
slowGameSpeed = false;
slowGameSpeedGUI = false;
shield = false;
hasBoostGUI = false;
}
function OnTriggerEnter(other : Collider)
{
if (other.gameObject.tag == "Truck" timeSinceLastCollision <= 0)
{
if (shield == false)
{
HealthControl.LIVES -= 1;
timeSinceLastCollision = 3;
dead = true;
Invoke ("deathReset", 0.5);
transform.position.y = 0;
transform.position.x = 0;
}
}
timeSinceLastCollision -= Time.deltaTime;
if (other.gameObject.tag == "Boost" hasBoost == false slowGameSpeed == false shield == false)
{
hasBoost = true;
hasBoostGUI = true;
Invoke ("boostReset", 3);
}
{
if(other.gameObject.tag == "TimeBoost")
{
//add time
Timer.timeLeft += 10;
}
}
if (other.gameObject.tag == "TimeSlow" slowGameSpeed == false shield == false hasBoost == false)
{
slowGameSpeed = true;
slowGameSpeedGUI = true;
hasBoost = true;
Invoke ("timeSlowReset", 1.5);
Invoke ("boostReset", 1.5);
}
if (other.gameObject.tag == "Shield" shield == false slowGameSpeed == false hasBoost == false)
{
shield = true;
Invoke ("shieldReset", 3);
}
}
public function Update()
{
if (dead == true)
{
shield = false;
hasBoost = false;
slowGameSpeed = false;
hasBoostGUI = false;
slowGameSpeedGUI = false;
}
if (slowGameSpeed == false)
{
Time.timeScale = 1.0;
}
if (slowGameSpeed == true)
{
Time.timeScale = 0.5;
}
if (hasBoost == true)
{
speed = boostSpeed;
}
if(hasBoost == false)
{
speed = defaultSpeed;
}
if (Input.GetKey (KeyCode.RightArrow) dead == false)
{
character.Move(Vector3.right * speed * direction * Time.deltaTime);
}
else
{
character.Move(Vector3.right * 0 * 0 * Time.deltaTime);
}
if (Input.GetKey (KeyCode.LeftArrow) dead == false)
{
character.Move(Vector3.left * speed * direction * Time.deltaTime);
}
else
{
character.Move(Vector3.left * 0 * 0 * Time.deltaTime);
}
if (Input.GetKey (KeyCode.UpArrow) dead == false)
{
character.Move(Vector3.up * speed * direction * Time.deltaTime);
}
else
{
character.Move(Vector3.up * 0 * 0 * Time.deltaTime);
}
if (Input.GetKey (KeyCode.DownArrow) dead == false)
{
character.Move(Vector3.down * speed * direction * Time.deltaTime);
}
else
{
character.Move(Vector3.down * 0 * 0 * Time.deltaTime);
}
}
function boostReset()
{
if(hasBoost == true);
hasBoostGUI = false;
hasBoost = false;
}
function timeSlowReset()
{
if (slowGameSpeed == true);
slowGameSpeed = false;
slowGameSpeedGUI =false;
}
function shieldReset()
{
if (shield == true);
shield = false;
}
function deathReset ()
{
if (dead == true);
dead = false;
}