Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(NGUI) why can't sprite A collide sprite B ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by coldpl_ay, Jul 7, 2014.

  1. coldpl_ay

    coldpl_ay

    Joined:
    Jan 20, 2014
    Posts:
    36
    Hi,guys.
    I'm using NGUI 3.6.0, Unity4.3.4f1.
    I want sprite A collide sprite B, so that sprite B can also be moved. I attach "Box Collider 2D", "Rigidbody 2D" to A and B.
    they both are at the depth 3.
    and A has an unique script "RandomForce" to give A a force (wrotten by myself). below is the content:
    " rigidbody2D.AddForce (new Vector2 (10, 10)); "
    main.png
    1.png

    but when I clicked "Run" button, A didn't touch B and then move away. Could anyone tell me what's the problem with my code. thanks sincerely.
    result.png
     
  2. Afro_Games

    Afro_Games

    Joined:
    Jul 1, 2013
    Posts:
    2
    Although your post is from 2014 and I am unsure if you still need this question answered, but for anyone else looking into this problem here is a possible lead to a solution.

    NGUI uses its sprites as Triggers and not collisions so instead of using void OnCollisionEnter(Collision collision) {} you must use void OnTriggerEnter(Collider other) {} instead, from there just take the difference between the 2 objs and apply that as a force in order to move the object in direction opposite of the collision. Hope this helps!