Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
This question was closed Apr 05, 2016 at 08:00 AM by Hellium for the following reason:

Duplicate Question. Please, make research, and follow the tutorials

http://unity3d.com/learn/tutorials/topics/physics

avatar image
0
Question by RealcakeTheBoss · Apr 05, 2016 at 07:59 AM · c#unity 52dcollision

Can't get object to destroy itself on collision.

I am trying to get a bullet object destroy itself on collision, in a 2D game. I read a page about collision by Unity and copied the code in, but I didn't get any results. My bullet object has a Rigidbody 2D with Continuous collision detention. I made sure everything was on the same Z coordinates and layer. Here is the coed for my bullet object.

using UnityEngine; using System.Collections;

public class Move_Trail : MonoBehaviour {

 public float moveSpeed = 5;
 
 void start()
 {
 }
 // Update is called once per frame
 void Update () {
     transform.Translate(Vector3.right * (Time.deltaTime ) * moveSpeed);
     Destroy(gameObject, 1);
 }

 void OnCollisionEnter2D(Collision2D coll)
 {
     Destroy(this.gameObject);
 }

 void OnCollisionEnter(Collision collisionInfo)
 {
     Destroy(this.gameObject);
     print("Detected collision between " + gameObject.name + " and " + collisionInfo.collider.name);
     print("There are " + collisionInfo.contacts.Length + " point(s) of contacts");
     print("Their relative velocity is " + collisionInfo.relativeVelocity);
 }

 void OnCollisionStay(Collision collisionInfo)
 {
     Destroy(this.gameObject);
     print(gameObject.name + " and " + collisionInfo.collider.name + " are still colliding");
 }

 void OnCollisionExit(Collision collisionInfo)
 {
     Destroy(this.gameObject);
     print(gameObject.name + " and " + collisionInfo.collider.name + " are no longer colliding");
 }


 void OnTriggerEnter(Collider other)
 {
     Destroy(this.gameObject);
     print("Collision detected with trigger object " + other.name);
 }

 void OnTriggerStay(Collider other)
 {
     Destroy(this.gameObject);
     print("Still colliding with trigger object " + other.name);
 }

 void OnTriggerExit(Collider other)
 {
     Destroy(this.gameObject);
     print(gameObject.name + " and trigger object " + other.name + " are no longer colliding");
 }

}

At this point, I am all out of ideas.

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 ShadoX · Apr 05, 2016 at 08:01 AM 0
Share

Try adding a print(..) to the OnCollisionEnter2D function to see if it's actually being triggered.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Stuck inside of Composite Collider when using Platform Effector 2D 2 Answers

how do i collide and kill the enemy while pressing space Unity 5 C# 2 Answers

What is the most effective way to structure Card Effects in a Single Player game? 1 Answer

Unity physics Help Implementing Real Life Physics in Jumping System C# 2 Answers

uNet hitboxes and movement. 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