I'm just about finished on a 2D shooter game and everything is working perfectly except for my score multiplier power up. I know the bool value is being set to true when the player picks it up but when I kill an enemy the value is false...not sure what's going on
here's my code for the power up
private GameObject objPlayer;
private AIscript scriptAI;
// Use this for initialization
void Start () {
objPlayer = (GameObject) GameObject.FindWithTag("Player");
scriptAI = (AIscript) objPlayer.GetComponent(typeof(AIscript));
}
void removeMe ()
{
Destroy(gameObject);
}
void OnTriggerEnter (Collider Other)
{
if (Other.gameObject.tag == "Player") //only player can trigger powerups
{
scriptAI.isMult = true;
Debug.Log("multi picked up!!");
removeMe();
}
}
and where the value is used in the character script
//boolean vars for power ups
public bool isLaser;
public bool isSpread;
public bool isMult;
private float powUpTime; //local timer variable for laser and spread power ups
private float powUpTime2; //local timer variable for score multiplier power up
private float powUpLength = 10f;
void Start () {
powUpTime = powUpLength;
powUpTime2 = powUpLength;
isLaser = false;
isSpread = false;
isMult = false;
}
void Update () {
//check for newly acquired power up and start timer
if (isLaser || isSpread)
{
powUpTime -= Time.deltaTime;
if (powUpTime <= 0)
{
isLaser = false;
isSpread = false;
powUpTime = powUpLength;
}
}
if (isMult)
{
powUpTime2 -= Time.deltaTime;
if (powUpTime2 <= 0)
{
isMult = false;
powUpTime2 = powUpLength;
}
}
}
void removeMe () //removes character
{
if (thisIsPlayer == false)
{
Instantiate(ptrScriptVariable.parAlienDeath, transform.position, Quaternion.identity);
GUIvarScript ptrScriptGUIvar = (GUIvarScript) objPlayerStats.GetComponent(typeof(GUIvarScript));
ptrScriptGUIvar.enemiesKilled += 1;
//check for multiplier power up
if(isMult)
{
Debug.Log("multi!!");
ptrScriptGUIvar.score += 20;
} else {
Debug.Log("no multi!!!");
ptrScriptGUIvar.score += 10;
}
} else {
Instantiate(ptrScriptVariable.parHumanDeath, transform.position, Quaternion.identity);
}
Destroy(gameObject);
}
i'm not sure how I could be losing the value because the logic seems right to me but I am fairly new to unity and C# so who knows