Quantcast
Channel: Latest Questions by Turkeybag
Viewing all articles
Browse latest Browse all 27

Clone Objects treating static variables strangly

$
0
0
Hey guys! I have an enemy that will duplicate itself every now and then. Whenever one is created I have a static variable "DupeMobCount" that increases by 1, and when they are destroyed, it decreases by 1. Whenever one of these enemies is created, it gains health equal to DupeMobCount * 2. Now as you can imagine, them always duplicating leads to all different amounts of "(Clone)" on the enemies. Some say it once, others 5 times. This is where things start to get really strange. If I don't kill any everything works as expected. They gain DupeMobCount * 2 in health. However if I kill a few, they start to gain additional health bases on the number of "(Clone)"s they have for no apparent reason. There seems to be no pattern to it. Here's the code (Everything you don't need to see removed): public static float DupeMobCount = 0; //I dragged the whole prefab with the script on it into Dupe, and it works fine apart from the above issue public MobStats Dupe; void Start (){ DupeMobCount ++; } if (NextDupe <= Time.time && DupeMobCount <= DupeCap) { NextDupe = Time.time + DupeTime; //MobStats is the script that stores mob health MobStats Duped = Instantiate(Dupe, VarTransform.position, VarTransform.rotation) as MobStats; Duped.Health += HealthPerDupe*DupeMobCount; } Also it might be important to mention these two things: 1) If I move the health gain into the start function then it seems that the health gain gets increased more and more for each (Clone) the object has rather than at a steady rate. 2) They also gain speed, damage and so on from DupeMobCount and that has no issues (it's calculated in update or DamagePlayer function, so pretty much when needed rather than at the start). I have no idea what the problem is, why it's happening, or how to fix it. Anyone have any ideas?

Viewing all articles
Browse latest Browse all 27

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>