Search Unity

2D Collision

Discussion in '2D' started by Xeonbg, Feb 18, 2019.

  1. Xeonbg

    Xeonbg

    Joined:
    Dec 20, 2017
    Posts:
    7
    I want to have an object be hit then be destroyed and I have no idea how to do that. I also have a tiny amount of knolage on collisions so that could be the issue to
     
  2. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    I need to see your code to try and help. Use code tags to upload your code please.
     
  3. Xeonbg

    Xeonbg

    Joined:
    Dec 20, 2017
    Posts:
    7
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Collision : MonoBehaviour {
    4.     private void OnTriggerEnter2D(Collider2D other)
    5.        
    6.     {
    7.         if (gameObject.name == "lever")
    8.         {
    9.             Destroy(GameObject.Find("Floor"));
    10.         }
    11.     }
    12. }
    13.  
    Here
     
  4. dusthound

    dusthound

    Joined:
    Sep 18, 2018
    Posts:
    98
    I think the error in your code is that you are not checking to see if the object you collide with is called "lever". Try replacing gameObject.name with other.name. Since you say you don't know much about collisions, look at the unity tutorial that focuses on that specific subject.