Write a script named EnemyDropItemProc that would be grabbed into an enemy or other item-droppable objects. There are some adjustable parameters in this class:
Enemy Level The enemies can be divided into several levels, there are 5 levels in the Shooter Example. It more likes that the enemy will drop the same level items when they killed by the player. Particular level means special.
Level Manager The pointer to the level manager in the scene. It will handle all item drop functions.
Drop Item Per The probability of the enemy to drop items when is killed.
The codes in script named EnemyDropItemProc are listed below.
Function DropItem will be called when the enemy is killed by the player. It would be called in Die function of Enemy script like this:
In script LevelManager, the function GenerateRandomItem , that will handle all random generate items process, can be write like this:
All droppable items would be managed in a script named ItemsCollection, it can return random , use function GenerateRandomLevelItem, or particular item from a particular item level list.
More details, please check the sample project here.
Written by
Blog Logo
Honglei Han 韩红雷
Published
Supported by
Image
Honglei Han 韩红雷的主页
Honglei Han from CUC
中国传媒大学 游戏设计 韩红雷
科研信息 所带课程 个人介绍 开源项目 创作的部分古体诗
Unity 3D 游戏引擎 Game Engine 游戏开发 计算机图形学 虚拟现实 Virtual Reality 程序设计 Programming