- Home /
Search and Destroy
Not the game sadly...
When a special bullet goes past the center of my screen it is supposed to destroy itself and then kill all enemies in a certain radius.
Heres my script for the bullet so far. (took out UN-related parts to be smaller)
var bulletSpeed: int;
var explosion: Transform;
function Update () {
if(transform.position.y >= 6){
Destroy(gameObject);
}
}
function OnTriggerEnter( otherObject: Collider ){
if(otherObject.gameObject.tag == "enemy"){
playerScript.playerScore += 100;
otherObject.gameObject.transform.position.y = 16;
otherObject.gameObject.transform.position.x = Random.Range(16,19);
var tempExplosion: Transform;
tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
Destroy(gameObject);
}
}
how can i make it so that the bullet kills all enemies in a certain area, or even just killing all enemies? thanks :D
Answer by qJake · Sep 07, 2010 at 12:21 AM
Use Physics.OverlapSphere, it returns all Colliders within a given sphere radius.
Edit: you use it like this:
// C#
Collider[] hits = Physics.OverlapSphere(transform.position, 5); // or some other position and radius here
foreach(Collider c in hits) { // Do something with the game objects here. // Access the game objects via c.gameObject. }
i'm sorry, i don't understand how that works, can you tell me? or show?
OverlapSphere returns an array of colliders, which you can then iterate through and destroy.
var victims[] = OverlapSphere (transform.position, explosionRadius);
If you're still having trouble (and SpikeX isn't around to update his answer), I can post more complete code.
Your answer
Follow this Question
Related Questions
get Collider[] as GameObject[] 1 Answer
how create a explode force collider 2 Answers
setting a transform var to an object that collided 1 Answer
How to add colliders to an array, and pick the oldest one? 1 Answer
Bomberman like explosion 0 Answers