I have a weird problem and I don’t have a clue why this doesn’t work:
I have a MonsterSpawner Script with some properties that are animated so the monsters gradually get harder: (js)
//animated properties var monsterMinDamageMultiplier:float=1.0; var monsterMaxDamageMultiplier:float=2.0; //... var monsterMinBulletSpeed:float=2.0; var monsterMaxBulletSpeed:float=2.0; //...
in here i’m periodically calling a spawn() function:
//spawn monster (before i'm figuring out the spawnPos somewhere of course) var newMonster:GameObject = GameObject.Instantiate(monsterType,Vector3(spawnPos.x,spawnPos.y,0.0),Quaternion.identity); var newMonsterGunController:MonsterGunController=newMonster.GetComponent(MonsterGunController); /... //set some properties of the monster based on animated properties of the script newMonsterGunController.damage = Random.Range(monsterMinDamageMultiplier,monsterMaxDamageMultiplier); newMonsterGunController.bulletSpeed = Random.Range(monsterMinBulletSpeed,monsterMaxBulletSpeed); /...
Now the funny part is that the damage multiplier works (and is set randomly between the min and max values), but the bulletSpeed multiplier doesn’t work. it’s always set to 2 (which is the default value).
During runtime i’m checking my monster spawner game object (that has this script attached) but it still looks like that:
I tried to Debug.Log() the min.max values out from the script on monster spawn and indeed, the min and max bullet speed values appear to be 2, but the min and max damage values are the proper animated values.
So I’m wondering: why can’t my script use one animated value, but the other one works? I also searched the script (and other scripts) and can’t find any other place where monsterMaxBulletSpeed and monsterMinBulletSpeed are used other than the two lines I posed above x…X