I have this command for the player to pick up speed boots which would speed the character up for a short period of time. This was all working fine, until I included the pragma directive. The issue Im having is that its not accepting the SpeedControl.QuickMovementSpeed(); call. I get a NullReferenceException error when I collide with the speed boot powerup object. It only has this issue with the Controller script which handles all the characters key movements. I know Im missing some code in the reference call.
I have multiple characters I want this to work for, not just one. I can assign each character to the Controller reference and it will work fine, but I want to make it universal through the script so all the characters can activate it. I know Im missing something in the SpeedControl = GetComponent(“Controller”) as Controller;. Each character tagged with the name of “Player”. I tried to add findGameObject.Find(“Player”) to the component call and it causes more problems. I hope what Im explaining makes sense. Anyone have an idea how to make this call work?
Thanks!
#pragma strict
var PowerupIcon : Texture2D;
var PowerupObject: GameObject;
var PowerupTimer : float = 0.0;
var PowerupCount : float = 0.0;
var activatePowerup : boolean;
var Boots : boolean = false;
private var GUIActive : boolean = true;
var SpeedControl : Controller;
var SpeedBoots : AllPowerupIcons;
var timerLabel : GUIText;
//Pre-reference components
function Start(){
SpeedControl = GetComponent("Controller") as Controller;
SpeedBoots = gameObject.Find("BootIcon").GetComponent("AllPowerupIcons") as AllPowerupIcons;
}
function Update(){
//Display timer
if(activatePowerup == true){
PowerupCount -= Time.deltaTime;
var timerValueCeil : float = Mathf.Ceil(PowerupCount);
if(timerValueCeil > 0)
{
timerLabel.text = timerValueCeil.ToString();
}
//Once the timer has reached 0, the speed goes back to original state
if(PowerupCount <= 0){
//Turn off timer
activatePowerup = false;
GUIActive = true;
timerLabel.text = " ";
//Reset timer
PowerupCount = PowerupTimer;
//Deactivate GUI
PowerupsOff();
Debug.Log("Times up!");
}
}
}
//Display powerup icon on GUI
function ApplyTexture(){
guiTexture.texture = PowerupIcon;
guiTexture.enabled = true;
}
//Destroy powerup icon on GUI
function DestroyTexture(){
guiTexture.enabled = false;
}
//Trigger system that will activate upon particular object collision.
function Powerups(){
//If true, activate speed boots
else if(Boots){
if(GUIActive){
SpeedControl.QuickMovementSpeed();
SpeedBoots.ApplyTexture();
}
//Dont let reactivate
GUIActive = false;
activatePowerup = true;
}
}