|
I've been working on a top down shooter, and I've made a simple enemy that follows the player and shoots projectiles. My problem is in my script, where I instantiate the projectile prefab. The script works just fine for one enemy, but once there is more than one enemy, the script conflicts with itself. (Note that each enemy has this script attached to it). The problem comes from the gameObject.find. The projectiles dont instantiate on their respective points of origin. If someone could enlighten me on how to get this script to only talk to itself, instead of each other enemy I would greatly appreciate it. I was hoping for something like... gameObject.find("/this.EnemyBulletSpawn") to refer to only the projectile spawn attached to the current object and not all the other enemies. Here is the code...
var bulletLive:boolean = false; var shotTimer = 1.5; function Update () { shoot(); } function shoot(){ if(bulletLive == false){
} function shotCoolDown(){ yield WaitForSeconds(shotTimer); bulletLive = false; } I'm sorry if this is messy, I'm new to the forum and if anyone could throw me a hint on code formatting, that would be appreciated too! Thanks in advanced!
(comments are locked)
|
|
Use transform.Find instead: http://unity3d.com/support/documentation/ScriptReference/Transform.Find.html It takes a path relative to the current object Thank you very much!!
Dec 11 '10 at 06:07 AM
Southpaw444
(comments are locked)
|

I don't know why my code sample is all broken up like that, sorry I'm a code newb.