Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

BoxCollider2D can't be used because of "things".

Discussion in 'Scripting' started by Username0101, Oct 1, 2015.

  1. Username0101

    Username0101

    Joined:
    Sep 3, 2015
    Posts:
    18
    It's 3:35AM here, I've been trying to get this to work for past 1.5 hours. I'm quite tired and can't really think with higher functions anymore. So I'll drop it here, maybe someone could help me find the solution.

    I'm trying to get (GameObject)Asteroid to OnTriggerEnter2D with (GameObject)Player. So I've set them both. Given them properties, and such.

    Asteroids inspector sneaky-peek.
    Player inspector sneaky-peek.

    There's an error to it. Most of solutions concluded that someone wasn't using OnTriggerEnter2D properly. Or that their code failed (what?). Sometimes image was transparent (which also created problems to them). Player is also partially transparent. Here's teh image.

    Changing collider in game manually by the 4 dots doesn't do anything. It doesn't change at all. The message doesn't go away either. The code attached to Asteroids is:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class asteroidMove : MonoBehaviour {
    5.  
    6.     public healthBar HPB;
    7.  
    8.     void Start() {
    9.       // Government secrets.
    10.     }
    11.  
    12.     void Update() {
    13.       // Cure for baldness.
    14.     }
    15.  
    16.     void OnTriggerEnter2D(Collider2D other) {
    17.         if (other.gameObject.name == "Player") {
    18.             Debug.Log ("Yea!");
    19.         }
    20.         Debug.Log (other.gameObject.name);
    21.     }
    22.  
    23. }
    If someone could help puzzling that out, that'd be early Christmas Gift.

    Goodnight!
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I think one of your objects needs a rigidbody2d before OnTriggerEnter2D will work.

    In regards to the "The collider did not create any collision...."
    I downloaded your image and noticed that everything was fine, until I rotated it 90 in the x like you did. That seems to be the issue. I dont think you are able to rotate 2d colliders like that. If you need it rotated like that, then you might need to use a regular boxcollider and flatten it a lot.

    Also, you can put your images right here in your post. There is no need to use another site for that ^^
    Just click "Upload a file" and choose your image. Then choose a spot to put it in your post and click "Full Image"
     
    Username0101 likes this.
  3. Username0101

    Username0101

    Joined:
    Sep 3, 2015
    Posts:
    18
    Yea, changing everything to regular 3D colliders and rigidbodies, solved the issue and now everything is triggered. Thanks.

    Just click "Upload a file" and choose your image. Then choose a spot to put it in your post and click "Full Image"
    I don't think that my posts need gigantic images in them :p
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I usually hide my images and code in spoilers like this
    ThisIsArt.png
    Spoilers can be found right over the code block button.
     
    Username0101 likes this.
  5. Username0101

    Username0101

    Joined:
    Sep 3, 2015
    Posts:
    18
    Hahaha, that derpy face. Spoiler: Click for Image, *Click*, Derp.
     
    HiddenMonk likes this.