• 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 largow · Apr 15, 2014 at 04:43 PM · 2dlistgameobjects

List of gameobjects attached to single object

Hey Guys, I'm making a 2D game. In some point I want that when my character goes through some position I want to 'shot him' with another game object. In other words, I got a hidden GameObject, and when my player walks into some kind of "detector" that hidden GameObject will start moving in the same direction my player is. So, if it touches him, he'll die.

You will see what I mean clearly in this video.

Check seconds 0.10 and 0.15. That's exactly what i want to do.

The issue is that i got that working, but every "detector" (in my case a detector is a BoxCollider2D wich is Trigger) can only have one gameObject (one spike) attached to it.

 public class ActivateSlider : MonoBehaviour {
 
     public EnemDesplazController slider; //I have to attach the slider on unity
 
     void OnTriggerEnter2D(Collider2D col){
         if (col.name == "Character") {
              slider.activated = true;
                      //this will go to my spike and activate it, so it'll start moving.
              this.GetComponent<BoxCollider2D>().enabled = false;
         }
     }
 }
 
 public class EnemDesplazController : MonoBehaviour {
     public bool activated = false;
         //Got some more variables here but they are related 
         //to the movement of the spike
     
     // Update is called once per frame
     void Update () {
 
         if (activated) {                
                     //Code that moves my spike. I ve already done it.    
         }
     }
 
      void OnTriggerEnter2D (Collider2D col){
          Respawn rsp = new Respawn ();
          rsp.OnTriggerEnter2D (col);
              //This method kills my player when the gameobject (spike) touches it.
     }
 }


So the question is, can I attach multiple objects to a detector? I mean, I'd like to do smething like this:

public class ActivateSlider : MonoBehaviour {

     public EnemDesplazController[] sliderLst; //And then on unity i will drag and drop every single spike.

Maybe there's a better way to do what I want. I'll be listening your advices.

Thanks in advance.

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 robertbu · Apr 15, 2014 at 06:21 PM 1
Share

There are many ways to solve this problem. One solution is to put the collider on an empty game object. Have that empty game object then inform each of the 'spike' game object to start moving. You can inform them by 1) sending a message to the objects, 2) directly calling a method on each object, or 3) using Events and Delegates to communicate to the objects. Figure out which and how will take some research on your part.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

A node in a childnode? 1 Answer

Should UI Canvas be used for games similar to 2048? 1 Answer

How can i detect how many objects of the same type i'm triggering and choose only one of them? 1 Answer

Rotate while moving forward 1 Answer

DontDestroyOnLoad & Singleton 2 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