Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Only one cloned enemy shoots

$
0
0
Currently I have 3 enemies spawning on the screen and I'm trying to get only my blue and red enemies to shoot and right now, the code works and finds a spawned enemy and allows only one to shoot. What I want is for all of my enemies that are present on the scene to shoot. I'll post my code so you can see what I'm doing. Note that it is WORKING, but it is not allowing all of my enemy clones to shoot. How can I fix this? function shootLazer() { Debug.Log("shootLazer Called"); shootTimer += Time.deltaTime; if (shootTimer < shootCoolDown) { return; } if(GameObject.Find("Enemy_Blue(Clone)")) { Debug.Log("Blue Enemy Shooting"); shootCoolDown = 1.5; shootTimer = 0; //Reset Timer var blueClone : GameObject; var blueProjectileOriginX = GameObject.Find("Enemy_Blue(Clone)").transform.position.x; var blueProjectileOriginY = GameObject.Find("Enemy_Blue(Clone)").transform.position.y-1; var blueProjectileOriginZ = GameObject.Find("Enemy_Blue(Clone)").transform.position.z; blueClone = Instantiate(enemyProjectile, Vector3(blueProjectileOriginX, blueProjectileOriginY, blueProjectileOriginZ), transform.rotation); blueClone.rigidbody.AddForce(blueClone.transform.up * -300); Destroy(blueClone.gameObject, 2); } if(GameObject.Find("Enemy_Red(Clone)")) { Debug.Log("Red Enemy Shooting"); shootCoolDown = 1.25; shootTimer = 0; //Reset Timer var redClone : GameObject; var redProjectileOriginX = GameObject.Find("Enemy_Red(Clone)").transform.position.x; var redProjectileOriginY = GameObject.Find("Enemy_Red(Clone)").transform.position.y-1; var redProjectileOriginZ = GameObject.Find("Enemy_Red(Clone)").transform.position.z; redClone = Instantiate(enemyProjectile, Vector3(redProjectileOriginX, redProjectileOriginY, redProjectileOriginZ), transform.rotation); redClone.rigidbody.AddForce(redClone.transform.up * -300); Destroy(redClone.gameObject, 2); } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>