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
-1
Question by danieljayb · Mar 21, 2012 at 08:22 PM · objectdestroycollide

destroy object on collision

trying to make some spheres I'm throwing disappear after a few seconds. i know i have some syntax wrong and i tried looking through reference but I'm not understanding whats wrong. heres my code:

 var speed = 3.0;
 var boxy:Transform;
 /////
 var player : GameObject;
 player = gameObject.tag =("player");
 ///////////
 var balls : GameObject;
 balls = gameObject.tag =("balls");
 /////////
 var floor: GameObject;
 floor = gameObject.tag =("floor");
 /////////////////
 
 
 function Update() { 
 
 if(Input.GetButtonDown("Fire1"))
 {
 
 var crate = Instantiate (boxy, transform.position, Quaternion.identity);
 
 crate.rigidbody.AddForce(transform.forward * 1000);
 
 
 
 }}
 function OnCollisionEnter (hit : Collision)
 
 { ///you are colliding
 
 Debug.Log("CollidingWithAnything");
 
 if(hit.gameObject.floor == hit.gameObject.balls){ //now colliding with certain object
 
 Debug.Log("Colliding With Certain"); 
 Destroy (balls, 2);
 
 }
 
 }
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 DaveA · Mar 21, 2012 at 08:23 PM 0
Share

You know, you can format this code by selecting it, then hit the 010/101 button above the text area. Please do.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 21, 2012 at 08:25 PM

if(hit.gameObject.floor == hit.gameObject.balls)

gameObject is a GameObject, and if you look in the Scripting Reference, you'll see that it contains neither 'floor' nor 'balls'. Generally folks use Tags to identify what hits Colliders.

Something like

if (hit.gameObject.tag == "balls")

Assuming you create a 'balls' tag and assign it to your ball objects

Comment
Add comment · Show 3 · 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 DaveA · Mar 21, 2012 at 08:51 PM 0
Share

Destroy(gameObject.tag == "balls", 4); no luck

if (hit.gameObject.tag == "balls") Destroy (hit.gameObject, 4);

avatar image danieljayb · Mar 21, 2012 at 08:55 PM 0
Share

do i declare a var for GameObject? whats it assigned? all i am understanding is that it is some floating syntax without an identity. I'm still unclear.

avatar image DaveA · Mar 22, 2012 at 01:07 AM 0
Share

Sorry, edited comment to fix it. If you use hit.gameObject it should work.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

C#: Changing current position of an object in y. 1 Answer

Destroy at collision based on color 3 Answers

Collision between objects 2 Answers

How do I delete a gamebject that is not the one my script is in? 2 Answers

Collision with a coin 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