unity3d - Unity C#, 2D game Spawning loot at selected location -


im making 2d game space shooter game in unity. issue loot spawning script. if enemies spawn @ fast rate loot spawn not @ destroyed enemy 1 of ones spawned.

the 2 scripts used detection , loot spawning:

public void ondeath(bool isdead) {     if (isdead == true)     {         if (random.value <= dropprobability)         {             instantiate(loot.transform, loot.transform.position = enemy.transform.position, quaternion.euler(0, 180, 0));         }     } } 

this script takes in 2 game objects first loot , second enemy. instantiate loot on position of enemy.

void update() {     if (healthpoints <= 0)     {         if (gameobject.comparetag("enemy"))         {             findobjectoftype<lootspawn>().ondeath(true);             destroy(this.gameobject);         }         else         {             destroy(this.gameobject);         }     }       }  private void ontriggerenter(collider other) {     if (other.gameobject.comparetag("ammo") != true)     {         if (other.gameobject.tag != this.gameobject.tag)         {             healthpoints--;             if (other.gameobject.comparetag("player1") == true)             {                 findobjectoftype<uielements>().removehealth();             }         }     } } 

this global script use "all" detection includes bullets, player , enemy. script works fine when spawn interval between each enemy higher 2.5seconds less causes issue i'll attach 2 screenshot visually show issue before shot, after shot

finally clarify want "loot" spawn @ "destroyed" enemy regardless of how many enemies on field or how fast instantiated onto field. without making code longer , making messy can point me in right direction? appreciate.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -