- Home /
Weird issue with first-time effect call on Android
It is hard to phrase the question above. I have a spawn system set up that works and works effectively.
There is a special effect that effects the spawn system from time to time. The wierd thing is that in the editor it functions without issue, everytime. How ever the first time this effect is triggered on Android the effect doesn't happen. Yet every time subsequent to that it works flawlessly. I have no idea why it is happening but it is frustrating to say the least. I will include my log and code below.
LogCat:
``` 05-27 14:08:33.091: I/Unity(18995): AAUNITY/GAME Fast Apples games played: 1 05-27 14:08:38.391: I/Unity(18995): AAUNITY/GAME Current combo count: 1 05-27 14:08:39.371: I/Unity(18995): AAUNITY/GAME Current combo count: 2 05-27 14:08:42.391: I/Unity(18995): AAUNITY/GAME Current combo total: 1 05-27 14:08:42.391: I/Unity(18995): AAUNITY/GAME Current game combo total: 1 05-27 14:08:44.381: I/Unity(18995): AAUNITY/GAME Current combo count: 1 05-27 14:08:46.352: I/Unity(18995): AAUNITY/GAME Gold Apple Caught 05-27 14:08:46.352: I/Unity(18995): AAUNITY/GAME Now activating Gold Effect 05-27 14:08:46.371: I/Unity(18995): AAUNITY/GAME Index 2: Super Frenzy 05-27 14:08:46.411: I/Unity(18995): AAUNITY/GAME Current Effect Before:NONE 05-27 14:08:46.411: I/Unity(18995): AAUNITY/GAME Current Effect After:SUPERFRENZY 05-27 14:08:46.421: I/Unity(18995): AAUNITY/GAME now adding to achievements 05-27 14:08:46.431: I/Unity(18995): AAUNITY/GAME now switching on/ Gold effect 05-27 14:09:06.441: I/Unity(18995): AAUNITY/GAME Gold Apple Caught 05-27 14:09:06.441: I/Unity(18995): AAUNITY/GAME Now activating Gold Effect 05-27 14:09:06.441: I/Unity(18995): AAUNITY/GAME Index 2: Super Frenzy 05-27 14:09:06.441: I/Unity(18995): AAUNITY/GAME Current Effect Before:NONE 05-27 14:09:06.451: I/Unity(18995): AAUNITY/GAME Current Effect After:SUPERFRENZY 05-27 14:09:06.451: I/Unity(18995): AAUNITY/GAME now adding to achievements 05-27 14:09:06.451: I/Unity(18995): AAUNITY/GAME now switching on/ Gold effect 05-27 14:09:06.561: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:06.751: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:06.961: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:07.151: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:07.371: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:07.571: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:07.751: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:07.901: I/Unity(18995): AAUNITY/GAME Current combo count: 1 05-27 14:09:07.951: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:08.161: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:08.331: I/Unity(18995): AAUNITY/GAME Current combo count: 2 05-27 14:09:08.361: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:08.551: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:08.581: I/Unity(18995): AAUNITY/GAME Current combo total: 1 05-27 14:09:08.581: I/Unity(18995): AAUNITY/GAME Current game combo total: 4 05-27 14:09:08.761: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:08.861: I/Unity(18995): AAUNITY/GAME Current combo count: 1 05-27 14:09:08.961: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:09.151: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:09.361: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:09.561: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:09.751: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:09.931: I/Unity(18995): AAUNITY/GAME Current combo count: 2 05-27 14:09:09.961: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:10.161: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:10.241: I/Unity(18995): AAUNITY/GAME Current combo total: 2 05-27 14:09:10.251: I/Unity(18995): AAUNITY/GAME Current game combo total: 5 05-27 14:09:10.371: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:10.561: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:10.641: I/Unity(18995): AAUNITY/GAME Current combo count: 1 05-27 14:09:10.761: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:10.961: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:11.111: I/Unity(18995): AAUNITY/GAME Current combo count: 2 05-27 14:09:11.161: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:11.371: I/Unity(18995): AAUNITY/GAME Super Frenzy Currently Active 05-27 14:09:11.701: I/Unity(18995): AAUNITY/GAME Current combo total: 3 05-27 14:09:11.701: I/Unity(18995): AAUNITY/GAME Current game combo total: 6 05-27 14:09:13.451: I/Unity(18995): AAUNITY/GAME Current combo count: 1 05-27 14:09:14.291: I/Unity(18995): AAUNITY/GAME Current combo count: 2 ```
Spawning code:
void SpawnNormalApple()
{
//add to gold and combo counters
comboCounter++;
goldCounter++;
Vector3 spawnPos = transform.position + new Vector3((float)spawns[0], 0, 0);
spawns.RemoveAt(0);
switch (goldScript.CURRENT_EFFECT)
{
case AppleCollider.GOLD_EFFECTS.FRENZY:
Debug.Log("AAUNITY/GAME Frenzy Currently Active");
if (random.Next(100) < 50)
{
Instantiate(comboPrefab1, spawnPos, Quaternion.identity);
}
else
{
Instantiate(comboPrefab2, spawnPos, Quaternion.identity);
}
break;
case AppleCollider.GOLD_EFFECTS.SUPERFRENZY:
Debug.Log("AAUNITY/GAME Super Frenzy Currently Active");
if (random.Next(100) < 50)
{
Instantiate(comboPrefab1, spawnPos, Quaternion.identity);
}
else
{
Instantiate(comboPrefab2, spawnPos, Quaternion.identity);
}
break;
case AppleCollider.GOLD_EFFECTS.REPEL:
Debug.Log("AAUNITY/GAME Repel Currently Active");
Instantiate(applePrefab, spawnPos, Quaternion.identity);
break;
default:
// Debug.Log ("AAUNITY/GAME No Gold Effects active or Gold Effect == Double Points");
if (random.Next(100) > 80)
{
Instantiate(rottenPrefab, spawnPos, Quaternion.identity);
}
else
{
Instantiate(applePrefab, spawnPos, Quaternion.identity);
}
break;
}
if (spawns.Count == 0)
refillSpawns();
if ((comboCounter == 5) && (goldCounter != 50))
{
comboCounter = 0;
SpawnComboApple();
}
else if (goldCounter == 50)
{
comboCounter = 0;
SpawnComboApple();
goldCounter = 0;
SpawnGoldApple();
}
}
effects code:
private void activateEffect()
{
string itemId = "";
goldEffectActive = true;
MersenneTwister random = new MersenneTwister();
int index = random.Next(1,4);
switch (index)
{
case 1:
Debug.Log("AAUNITY/GAME Index " + index + ": Frenzy");
if (firstCatch)
{
animGold.gameObject.SetActive(true);
animGold.Play("Frenzy");
// The delegate is used here to return to the previously
// playing clip after the "hit" animation is done playing.
animGold.animationCompleteDelegate = AnimFinishedDelegate;
}
break;
case 2:
Debug.Log("AAUNITY/GAME Index " + index + ": Super Frenzy");
if (firstCatch)
{
animGold.gameObject.SetActive(true);
animGold.Play("Super Frenzy");
// The delegate is used here to return to the previously
// playing clip after the "hit" animation is done playing.
animGold.animationCompleteDelegate = AnimFinishedDelegate;
}
break;
case 3:
Debug.Log("AAUNITY/GAME Index " + index + ": Double Points");
if (firstCatch)
{
animGold.gameObject.SetActive(true);
animGold.Play("Double");
// The delegate is used here to return to the previously
// playing clip after the "hit" animation is done playing.
animGold.animationCompleteDelegate = AnimFinishedDelegate;
}
break;
case 4:
Debug.Log("AAUNITY/GAME Index " + index + ": Repellent");
if (firstCatch)
{
animGold.gameObject.SetActive(true);
animGold.Play("Repellent");
// The delegate is used here to return to the previously
// playing clip after the "hit" animation is done playing.
animGold.animationCompleteDelegate = AnimFinishedDelegate;
}
break;
}
// set the item id for the store invetory retrival
switch (index)
{
case 1: // Frenzy
Debug.Log("AAUNITY/GAME Current Effect Before:" + CURRENT_EFFECT);
CURRENT_EFFECT = GOLD_EFFECTS.FRENZY;
Debug.Log("AAUNITY/GAME Current Effect After:" + CURRENT_EFFECT);
itemId = AndysApplesAssets.FRENZY_GOOD.ItemId;
break;
case 2: // Super Frenzy
Debug.Log("AAUNITY/GAME Current Effect Before:" + CURRENT_EFFECT);
CURRENT_EFFECT = GOLD_EFFECTS.SUPERFRENZY;
Debug.Log("AAUNITY/GAME Current Effect After:" + CURRENT_EFFECT);
itemId = AndysApplesAssets.SUPER_GOOD.ItemId;
break;
case 3: // Double Points
Debug.Log("AAUNITY/GAME Current Effect Before:" + CURRENT_EFFECT);
CURRENT_EFFECT = GOLD_EFFECTS.DOUBLE;
Debug.Log("AAUNITY/GAME Current Effect After:" + CURRENT_EFFECT);
itemId = AndysApplesAssets.DOUBLE_GOOD.ItemId;
break;
case 4: // Repellent
Debug.Log("AAUNITY/GAME Current Effect Before:" + CURRENT_EFFECT);
CURRENT_EFFECT = GOLD_EFFECTS.REPEL;
Debug.Log("AAUNITY/GAME Current Effect After:" + CURRENT_EFFECT);
itemId = AndysApplesAssets.REPELLENT_GOOD.ItemId;
break;
}
Debug.Log("AAUNITY/GAME now adding to achievements");
achievementTracker.AddProgressToAchievement("Gold Standard", 1.0f);
if (firstCatch)
{
firstCatch = !firstCatch;
spawnScript.firstCatchGold();
}
GE_INDEX = index;
Debug.Log("AAUNITY/GAME now switching on/ Gold effect");
switch (CURRENT_EFFECT)
{
case GOLD_EFFECTS.FRENZY:
achievementTracker.AddProgressToAchievement("Frenzy Fanatic", 1.0f);
achievementTracker.AddProgressToAchievement("Fred's Frenzy Bonanaza", 1.0f);
if (StoreInventory.GetGoodUpgradeLevel(itemId) < 6)
effectTimer += StoreInventory.GetGoodUpgradeLevel(itemId);
else
effectTimer += 5;
break;
case GOLD_EFFECTS.SUPERFRENZY:
achievementTracker.AddProgressToAchievement("Raining Combos", 1.0f);
achievementTracker.AddProgressToAchievement("Super Frenzy Wizard", 1.0f);
incrementSuperFrenzyAchievements();
if (StoreInventory.GetGoodUpgradeLevel(itemId) < 6)
effectTimer += StoreInventory.GetGoodUpgradeLevel(itemId);
else
effectTimer += 5;
break;
case GOLD_EFFECTS.DOUBLE:
achievementTracker.AddProgressToAchievement("Twice The Charm", 1.0f);
achievementTracker.AddProgressToAchievement("2X Mastery", 1.0f);
if (StoreInventory.GetGoodUpgradeLevel(itemId) < 6)
effectTimer += StoreInventory.GetGoodUpgradeLevel(itemId);
else
effectTimer += 5;
break;
case GOLD_EFFECTS.REPEL:
achievementTracker.AddProgressToAchievement("Honor System", 1.0f);
achievementTracker.AddProgressToAchievement("No No to Rottens", 1.0f);
if (StoreInventory.GetGoodUpgradeLevel(itemId) < 6)
effectTimer += StoreInventory.GetGoodUpgradeLevel(itemId);
else
effectTimer += 5;
break;
default:
break;
}
Invoke("deactivateEffect", (float)effectTimer);
}
public void deactivateEffect()
{
GE_INDEX = 0;
LAST_EFFECT = CURRENT_EFFECT;
CURRENT_EFFECT = GOLD_EFFECTS.NONE;
goldEffectActive = false;
effectTimer = 5;
}
update 5/28/13: OK this is wierd but despite this code that sets the effect timer to 5.
void Start()
{
// Code above this
effectTimer = 5;
// ... more code
}
When run on android device it will set the effectTimer to an initial value of 0. As proved by the following log statement ``` 05-28 12:16:31.041: I/Unity(20876): AAUNITY/GAME Effect timer length for Gold Effect FRENZY is 0 seconds. ```
so I just set an if statement to check for this on the first time only and set it back to its default time and that solved the issue. Still have no idea why this was the case, nor why it only occurred on Android.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Calling an android method from Unity3D with a JAR plugin 0 Answers
Procedural Spawning Theorems 0 Answers
C++ windows DLL and Android? 1 Answer
Smooth Follow Camera Rotate on Z-Axis? 2 Answers