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 Nelis · Mar 07, 2013 at 04:13 PM · 2djavascriptgameobjectdestroycoordinates

Erasing a gameobject if you have the coordinates.

Hi, I have a cube that moves left and right (2D). It moves on a grid of cubes (so a cube at x = 1 and y = 1, another cube at x=2 and y = 1 and so on). All the cubes are 1 by 1 by 1. My question is, if I press the down button, the cube closest under gets destroyed. Is there a way to destroy a game object if you have the coordinates? (btw, I'm working js). Thank you. -Nelis

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

3 Replies

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

Answer by Kiloblargh · Mar 07, 2013 at 06:34 PM

You don't need to use colliders for your simple application. Just a 2d array.

Add a reference to each object into the array when it is created.

 var theGrid : GameObject[,];
 var myTransform : Transform;
 var myX : int;
 var myY : int;

 //in awake
 theGrid = new GameObject[32,32];

 //in the movement function
 myX = Mathf.Round(myTransform.position.x);
 myY = Mathf.FloorToInt(myTransform.position.y);

 //in the dig function
 if (theGrid[myX,myY-1])
     {
     Destroy(theGrid[myX,myY-1],0.1);
     }
 

BTW are you making a Lode Runner derivative? That was one of my favorite ancient PC games.

Comment
Add comment · Show 2 · 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 Nelis · Mar 07, 2013 at 06:57 PM 0
Share

I don't know that game but I don't think so. I think i get your way of doing it, but i don't know hope to incorporate it into my game. $$anonymous$$y project folder is in the latest comment to highpockets. Would you want to help me? (Btw, I'm making a game like $$anonymous$$otherload.)

avatar image Kiloblargh · Mar 07, 2013 at 10:07 PM 0
Share

I don't have Unity 4 yet and I'm too busy to really help; but I looked at your scripts. You should probably start over with a single script that controls all the gameplay. $$anonymous$$eep CameraScript separate, but all the others should be one script. The way you've set it up now, you will need to create script variables (the type of a js is its name) and drag the other scripts onto them on in the inspector, then Erase can access variables and functions in 2D$$anonymous$$apGrid, for example. But that structure gets tiresome fast and it will cause long build times if taken to an extreme.

avatar image
0

Answer by Ankit Priyarup · Mar 07, 2013 at 05:25 PM

Search the game object which have following coordinates n java script then destroy it

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 AlucardJay · Mar 07, 2013 at 09:14 PM 0
Share

I keep finding these by you, Please refrain from leaving this kind of one-line answer that just doesn't make sense. Use the add new comment button.

Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

Here at Unity Answers, Answer means Solution, not Response.

Watch this : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

avatar image
0

Answer by highpockets · Mar 07, 2013 at 05:49 PM

Have you tried checking the isTrigger in your box collider? You can handle this through trigger events. For example, you could set a cube that is moving to layer 8 by using a bool to find out if it's moving. Then:

 if( moving )
 {
 
 gameObject.layer = 8
 }

Then you can check if that collider enters or stays on a trigger. OnTriggerEnter or OnTriggerStay. Here is an example with OnTriggerEnter.

  function OnTriggerEnter( other : Collider )
     {
     
     if( other.gameObject.layer == 8 )
     {
     
     Destroy( gameObject );
     }

Hope that helps.

Comment
Add comment · Show 2 · 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 highpockets · Mar 07, 2013 at 05:51 PM 0
Share

One entity in the trigger must have a rigidbody. If you already handle movement without a rigid body, then check is$$anonymous$$inematic in the rigid body component.

avatar image Nelis · Mar 07, 2013 at 06:27 PM 0
Share

I think I did what you said, but it's not working. Here is my project folder, I hope it clarifies what my intention is: http://www.mediafire.com/?4kndffgr84t9y8j BTW, I have deleted your code again in my script...

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

13 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Trying to make a simple inventory: 0 Answers

Confused about GameObject and Transform 1 Answer

What is wrong with my script? 1 Answer

Co Routine 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