GetComponent issue

Updated on May 16, 2016 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on May 15, 2016

Hi everyone,

I think I have a minor issue, but I can’t spot the mistake. I have two scripts, script A and B.

In script A, the following integer is increased to value from 0 to 1:
shieldCounter

In script B, I define the following:


void Update () {

shieldCounterTwo = shieldSpawnPrefab.GetComponent<AbilityShieldSpawn>().shieldCounter;

...}

Unfortunately, however, shieldCounterTwo does not assume value 1, but remains stuck at 0. These exact scripts were previously applied to another ability in the game and worked fine. With this shield ability, on the other hand, something went wrong.

Thx in advance

  • Liked by
Reply
0 on May 15, 2016

make the shieldCounter be in Update function or just make run every second. And how did you make the shieldCounter increased by one? can i see the code

  • Liked by
Reply
Cancel
0 on May 16, 2016

shieldCounter increases by 1 in the following way:

public int shieldCounter = 0;
 private bool shieldAbilityDestructionCheck;
void CheckAbilityExistance(){
 if (shieldAbilityDestructionCheck == true) {
 shieldCounter += 1;
 AbilityShieldTouch.shieldAbilityDestruction = false;
 }
 }
void Update () {
 Invoke ("CheckAbilityExistance",0f);
...}

Strange thing is I have the exact same script for another ability and it works..

P.S. I did not include the full code since it’s 46 lines and I believe it is not useful for solving this issue.

  • Liked by
Reply
Cancel