Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

I Need Help for Pickup Script

Discussion in 'Getting Started' started by GameDeveloperFromUnity, Feb 3, 2015.

  1. GameDeveloperFromUnity


    Jan 7, 2015
    Hey Guys, I need help for a pickup script that can make the coin pickabale. I dont whant any triggers or colliders or roll a ball they dont work so please just paste the script! please test it and see if it works I got Unity 3D 4.6.0 Free Version
  2. runevision


    Nov 28, 2007

    Triggers normally work fine and is the easiest way to check for overlaps/collision with pickups. If it didn't work for you, maybe there was something that wasn't setup correctly in your project? Is there some specific reason you don't want to user triggers?

    Also, you said the Roll A Ball tutorial ( didn't work for you. I'm not aware of any known problems with it, so again it might be something that you setup incorrectly. Can you be more specific about what it was that didn't work for you?
  3. GameDeveloperFromUnity


    Jan 7, 2015
  4. boolfone


    Oct 2, 2014
    I watched the video about picking up stuff in Roll A Ball and created a small test of the ideas:

    There is one bit of trickiness that got me at first. It is explained here:

    It says “Note that trigger events are only sent if one of the colliders also has a rigidbody attached.”

    Anyhow, to get it working, I attached a rigidbody to the player.

    Also, I basically put this in a script and attached it to the player:

    Code (CSharp):
    1. void OnTriggerEnter(Collider other)
    2. {
    3.    print ("entered");
    4.    other.gameObject.SetActive (false);
    5. }
    Also, I had a trivial movement script attached to the player with this:

    Code (CSharp):
    1. void Update () {
    2.    transform.Translate (0f, 0f, 0.01f);
    3. }
  5. Kiwasi


    Dec 5, 2013
    The only known problem with Roll-A-Ball is the obsolete references to GUIText.There is an updated version on my channel. Watching Roll-A-Ball is probably the best way to learn this.

    But here are the basic instructions anyway.

    • Add a RigidBody to your player
    • Add a collider to your player. IsTrigger should not be clicked.
    • Add a collider to your coin, IsTrigger should be clicked.
    • Add the following script to the coin
    Code (CSharp):
    1. void OnTriggerEnter (Collider other){
    2.     Debug.Log("You picked up a coin");
    3.     Destroy(gameObject);
    4. }
    If your coins move they should also have rigidbodies.

    You know not what you ask for. Doing this without triggers is certainly possible, but would require writing a custom physics engine. This only makes sense in a few edge cases (like an RTS on the scale of supreme commander). You could use distance checking every frame, but this will be more expensive then triggers in PhysX. Unless you already know how to use octrees for spatial partitioning.