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 /
This question was closed Dec 16, 2016 at 12:20 PM by Vylax for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Vylax · Dec 16, 2016 at 11:58 AM · gameobjectscollisions

Add a GameObject to a list OnCollisionEnter and remove it from the list OnCollisionExit

Hi, I got severals objects colliding to a cube and I would like to add them to a GameObject[] OnCollisionEnter(); then I want to remove them if they go away.

I tried this for the first part :

 var Enemies : GameObject[];
 
 function OnCollisionEnter (other : Collision) {
 Enemies(x) = other.gameObject;
 }
 
 function OnCollisionExit (other : Collision) {
 Enemies(x) = null;
 }

as you can see, my problem is that I don't know how to remove the cube that is colliding or not...

Example: Cube 1 is the one that I apply the script, cube 2, 3 and 4 dont hit it,

few seconds later cubes 2 and 4 are colliding the cube 1 but cube 3 is still away,

here I would like to apply damage to cubes 2 and 4,

then cube 2 go away so only cube 4 is collinding cube 1,

(fixed)here is my problem, I don't know how to remove only cube 2 from the list because I don't know how to get the number of a cube in the list, to remove the correct one...(fixed)

the new problem is how to apply damage to all gameObjects in Enemies[]; ???

hope you can understand what I mean...

Comment
Add comment · Show 1
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 Vylax · Dec 16, 2016 at 12:03 PM 0
Share

I just think to this :

 function OnCollisionEnter (other : Collision) {
 y += 1;
 other.gameObject.GetComponent(number).x = y;
 Enemies(other.gameObject.GetComponent(number).x) = other.gameObject;
 }
 
 function OnCollisionExit (other : Collision) {
 Enemies(other.gameObject.GetComponent(number).x) = null;
 }


this might be the solution, can't test it right now so the next problem is how to apply damage to all gameObjects in Enemies[]; ???

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Vylax · Dec 16, 2016 at 12:20 PM

found the solution :

 for(i : int = 0; i < closeEnemies.Lengt; i++) {
 if(closeEnemies(i) != null) {
 closeEnemies(i).gameObject.GetComponent(enemy).health -= damage;
 }else{
 i++;
 }
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

Follow this Question

Answers Answers and Comments

59 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 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

Dictionary with GameObject as key is updating values under other keys 1 Answer

Changing array materials on collision (c#) 1 Answer

How to use rigidbody.MovePosition within OnTrigger? 0 Answers

Click to Move with CharacterController 1 Answer

Inconsistent Trigger events 1 Answer


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