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 mazket · Nov 26, 2014 at 03:07 PM · 2dspawn2d-physicscollider 2d

2D Colliders and spawners check

I'm have no idea what can I may missing for this setting:

have 2 sprites, each one with the respective 2d colliders and 2d rigid bodies. when sprite A goes to sprite B, sprite B will be deleted, to do so I have attached on sprite B a script with the following:

     using UnityEngine;
     using System.Collections;
     
     public class Interaction: MonoBehaviour {
     
         void OnCollisionEnter2D(){
     
             Destroy (this);
         }
     }


but nothing happens, put a debug before destroy but didn't display it, also put sprite A and B on different layers and setup it on project setting-> physic and still nothing, what I'm missing??

Now with the spawner I want:

I have an empty object that have 5 child empty object those one are my spawners. each one create a box, when one of the boxes moves from it original postion the spawner will generate a new box. At first I wanted to have a null checker but I failed. this was what I had:

     using UnityEngine;
     using System.Collections;
     
     public class Spawn: MonoBehaviour {
     
     public GameObject Box;
 
     void Updated (){
    
       if (Box = null){
 
          spawn();
       }
     }
 
     void Awake(){
     
        Spawn();
     }
 
     void Spawn(){
   
         GameObject newBox = Instantiate(Box, transform.position, transform.rotation) as GameObject;
         newBox.name = "Box";
     }

It created the awake box, but later on do nothing else, I put the prefab but after create the awake box it box is none in the inspevtor.

also tried colliders for the spanwer like this:

 using UnityEngine;
 using System.Collections;
 
 public class Spawner : MonoBehaviour {
 
     public GameObject box;
     public int boxnum = 0;
     
     void OnCollisionExit2D () {            
 
         if (boxnum == 0){
 
             Spawn();
         }        
     }
 
     void Awake() {
 
         Spawn ();
     }
 
     void Spawn(){
 
         GameObject newbox = Instantiate(box, transform.position, transform.rotation) as GameObject;
         newbox.name = "box";
         boxnum++;
     }
 }

all good but one detail is that this script goes to each spawner and I have another script that getcomponent and call for boxnum and add, so the problem is that it only send the information to only one spawner, as a mere of fact the first on the inspector and doing so alter the result, If the box of the 1st spawner moves generates the other box as desire, but if a box of the other 4 spawner moves the count of the 1st inspector is the one the get altered instead of the respective spawner so the spawner doesn't create a new box, What can I do??

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 Landern · Nov 26, 2014 at 03:08 PM 0
Share

Your collisions are incorrect, they take an argument of type Collision2D, this is clearly stated in the documentation. The method signatures must match for unity to make the call.

OnCollisionEnter2D

OnCollisionExit2D

avatar image mazket · Nov 26, 2014 at 08:42 PM 0
Share

yeah!!! totally forgot about Collision2d on the void, THAN$$anonymous$$S man.

Half problem solve, a quick note for the spawners if I try gameobject.findwithtag("name"). should I try getcomponent in plurar or singular so the script goes to every objects related or will do no difference?

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to give a direction to a hook? 1 Answer

2D going through walls bug 1 Answer

RigidbobyConstraints2D is not working in Unity 5.0.2f1 Personal Edition!! 0 Answers

2D Realistic Space Collision. 1 Answer

How do I stop my sprite from jumping in the air? 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