Losing power up bool value

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 ()
 void OnTriggerEnter (Collider Other)
     if (Other.gameObject.tag == "Player") //only player can trigger powerups
         scriptAI.isMult = true;
         Debug.Log("multi picked up!!");

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
                ptrScriptGUIvar.score += 20;
            } else {
                Debug.Log("no multi!!!");
                ptrScriptGUIvar.score += 10;
        } else {
            Instantiate(ptrScriptVariable.parHumanDeath, transform.position, Quaternion.identity);
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

more ▼

asked May 26, 2011 at 08:15 PM

nroot86 gravatar image

1 3 2 5

It would help if you edit your question to have correct code formatting.

May 26, 2011 at 08:22 PM almo

ive tried to...it keeps coming out like that

May 26, 2011 at 08:23 PM nroot86

Edited so the code was formatted properly - QATO was playing uo by the looks of it. I'll take a look at the question now...

May 26, 2011 at 08:29 PM GesterX

Messed up still. Some of the code is missing now...

May 26, 2011 at 08:30 PM almo

fixed it..finally

May 26, 2011 at 08:34 PM nroot86
show all comments (comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

When the player picks up a multiplier, it sets isMulti = true in the player's instance of AIScript. When the enemies die, they check if isMulti is true in their own instance. When they die, they need to check the instance on the player.

more ▼

answered May 26, 2011 at 08:42 PM

almo gravatar image

2k 14 14 33

removeMe() is a function in AIscript that gets called from Update if the health of either the enemy or the player is <= 0. sorry if this was unclear, I removed parts of the code to keep it less cumbersome

May 26, 2011 at 08:48 PM nroot86

I was always curious how variables were called when one can attach an object to the Inspector view. So it is simply called "ScriptName" object be it a variable or another object?

Thanks CSDG

May 26, 2011 at 08:48 PM UniteMage

I think I got it. Take a look at the edited answer.

May 26, 2011 at 08:54 PM almo

got it! used a pointer to the player's instance of AIscript and it's working now. Thanks for the help, the instance stuff has been the hardest thing for me to grasp

May 26, 2011 at 09:02 PM nroot86

Excellent! If this answer helped, you should "accept" it as the correct answer. Just click the little checkmark by the thumbs.

May 26, 2011 at 09:36 PM almo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: May 26, 2011 at 08:15 PM

Seen: 1561 times

Last Updated: May 26, 2011 at 09:36 PM