Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Jan 06, 2016 at 08:47 PM by Aleg8r for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Aleg8r · Jan 04, 2016 at 11:31 AM · javascripttagcollision issuesenemy health

Collision killing all enemies not the one the player collides with

As title says killing all enemies with tag enemy , all in Java

Fly (enemy) Collision Code:

 #pragma strict
 
 function OnCollisionEnter2D(collision2D: Collision2D ){
     var gameManager = GameObject.FindGameObjectWithTag("GameController");
     //var player = GameObject.FindGameObjectWithTag("Player");
     //var fly = GameObject.FindGameObjectWithTag("Fly");
     if (collision2D.gameObject.tag == "Player"){
         gameManager.SendMessage ("DeathFly");
     }
 }

GameManager code : (only the parts for the enemies as its a long script)

 #pragma strict
 
 var fly : GameObject;
 
 function DeathFly(){
     fly = GameObject.FindGameObjectWithTag("Enemy");
     fly.SendMessage("Kill");
 }
 
 

Fly (enemy) Code :

 #pragma strict
 
 var damage : int = 10;
 var health : int = 10;
 var hitSound : AudioClip;
 var flySound : AudioClip;
 var deathSound : AudioClip;
 var Boost : GameObject;
 
 var healthBar : UI.Slider;
 
 function Update(){
     var audio : AudioSource = GetComponent.<AudioSource>();
     if(health == 0){
         AudioSource.PlayClipAtPoint(deathSound, Camera.main.transform.position);
         Kill();
     }
 
     healthBar.value = health;
 }
 
 function Kill(){
     Boost = Instantiate(Resources.Load("Prefabs/Cloud"), transform.position, transform.rotation) as GameObject;
     Destroy(this.gameObject);
 }
 
 function ApplyDamage(){
     health = health -= damage;
 }


if anyone could help with killing when landing on the head i would be very great full.

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by Adam-Halley-Prinable · Jan 04, 2016 at 01:25 PM

Try replacing the fly collision code with this:

  function OnCollisionEnter2D(collision2D: Collision2D ){
      if (collision2D.gameObject.tag == "Player"){
          GetComponent<INSERT_NAME_OF_FLY_CODE_FILE_HERE>().Kill();
      }
  }


And in the fly code, add the word "public" in front of "function Kill(){"

This is assuming the fly collision code and the fly logic code are both attached to the same fly game object.

Comment
Add comment · 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
1

Answer by Aleg8r · Jan 04, 2016 at 02:21 PM

Thanks SOOO much been messing with this for hours

Comment
Add comment · Show 1 · 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 Adam-Halley-Prinable · Jan 04, 2016 at 02:25 PM 0
Share

No worries :) Choose me as the accepted answer? Gotta get dat sweet sweet reputation!

Follow this Question

Answers Answers and Comments

39 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I use arrays, with getcomponent? 2 Answers

BCE0043, BCE0044 and UCE0001 errors after upgrade from 4.3 to 5.3 0 Answers

Save system 1 Answer

GameObject, Select Parent As Object 0 Answers

Writing save files (JavaScript) 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