Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Danor · Oct 15, 2014 at 09:42 PM · javascript

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;
 }*/
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MrSoad · Oct 15, 2014 at 09:52 PM 0
Share

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?

avatar image Danor · Oct 16, 2014 at 12:27 AM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Danor · Oct 16, 2014 at 12:37 AM 0
Share

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 :)

avatar image robertbu · Oct 16, 2014 at 01:01 AM 0
Share

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().

avatar image Danor · Oct 16, 2014 at 09:55 AM 0
Share

your right and it works, thanks again mate

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges