- Home /
making a trail that destroys enemies
after searching for a way to do this i found a script from robertbu that should work for detecting collisions, i'm trying to make it so that when this system detects a collision with "Virus" by using other.CompareTag like you would with ontriggerenter(other:collider). Here's the neccesary part of the script.
function Update() {
if (Hit() == true){
if (other.CompareTag("Virus")){
Destroy(other.gameObject);
}
}
}
function Hit() : boolean {
var i = head;
var j = (head - 1);
if (j < 0) j = arv3.Length - 1;
while (j != head) {
if (Physics.Linecast(arv3[i], arv3[j], hit))
return true;
i = i - 1;
if (i < 0) i = arv3.Length - 1;
j = j - 1;
if (j < 0) j = arv3.Length - 1;
}
return false;
}*/
Have you tried putting some Debug.Log's in to find out what is and is not being executed. What exactly is not happening when you run the game?
i should've said this in the original post that i get errors on the .other, it can't use .other so i was mainly looking for a different way to do it but provided the .other to specify the kind of thing i'm trying to achieve, sorry i should've been more clear
Answer by robertbu · Oct 15, 2014 at 11:40 PM
If I understand correctly, replace lines 16 and 17 with:
if (Physics.Linecast(arv3[i], arv3[j], hit) && hit.collider.tag == "Virus") {
Destory(hit.collider.gameObject);
}
With this change, you don't want to return a boolean.
thanks for replying i was hoping to get an answer from you ;)
this works
function Update() {
if (Hit()){
Destroy(hit.collider.gameObject);
}
}
function Hit() : boolean {
var i = head;
var j = (head - 1);
if (j < 0) j = arv3.Length - 1;
while (j != head) {
if (Physics.Linecast(arv3[i], arv3[j], hit) && hit.collider.tag == "Virus") {
Destroy(hit.collider.gameObject);
}
i = i - 1;
if (i < 0) i = arv3.Length - 1;
j = j - 1;
if (j < 0) j = arv3.Length - 1;
}
return false;
}
thank you so much :)
You code has a few issues. First, you have destroy twice...once in Update() and once in the Hit(). But since Hit will always return false, the second one will never fire. Change your function to:
function Hit() {
Then delete line 22, and call it in Update as:
function Update() {
Hit();
}
Structured this way, all game objects tagged with 'Virus' that collide will be Destroyed().
Your answer
![](https://koobas.hobune.stream/wayback/20220613165206im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A node in a childnode? 1 Answer
[HELP] BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.GameObject'. 1 Answer
Unable to access the function of Category class inside the iOS library in Unity 0 Answers
What should i learn for unity C# or UnityScript? 4 Answers
Hide the ImageTraget in Real world 0 Answers