|
Hi I am trying to get items to appear when an object box is destroyed, I have tried looking at the enemy damage script in the lerpz tutorial for reference and I would just like to understand why the script only works with the copper prefab. To be clear all I really want is to destroy a box and have items left in its place. I am sure there is a simple reason and/or something I am missing, if someone could please help me understand this I would be most grateful.
(comments are locked)
|
|
I'll start off simple and edit if you need more clarification. There are multiple ways to accomplish what you are trying to do. This is one. The basic steps are as follows:
Steps 4 and 5 may need to be swapped, depending on your design. Examples: The following scripts can be attached to your box and the boxDestroyed variable updated by other scripts. Or you can incorporate the code into the script that currently controls the box's destruction. Javascript Version
C# Version Hi Steve, thank you for responding and for taking the time to write a script for me, just so you know my understanding of java script is minimal at best (it took me 2 days to implement a score system!) so when I look at C# script i really don't get it at all, i am guessing that your script requires a function Apply Damage but that it is not written like that in C#. Thank you again for your help.
Aug 28 '10 at 11:13 AM
Simon 5
I've updated the answer with a Javascript version, but I'm going to avoid the temptation to expand the answer to cover multiple topics. The example scripts can be used in two ways: Add the script to the object and have another script update the boxDestroyed variable when the object is destroyed. Or incorporate the example code into the script that controls box destruction. Since you are new to programming, concentrate on understanding the core concepts of what the the example script is doing. After that it should be easier to figure out how to incorporate those concepts into your scripts.
Aug 28 '10 at 03:11 PM
SteveFSP
(comments are locked)
|

Could you be more specific? The EnemyDamage script in the tutorial will work with anything, there is nothing specific to any prefab in that script. As long as you call the ApplyDamage function with greater than or equal to the hit points or even calling the Die function directly, whatever prefab you have set in the script attached to the gameObject instance will be instantiated in its place and the prefab drops that you set dropped