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

Cube on platform (Help!)

Discussion in 'Scripting' started by niick555, Sep 26, 2014.

  1. niick555

    niick555

    Joined:
    Sep 19, 2014
    Posts:
    11
    Good afternoon guys, okay? Well, I'm new to Unity 3D and I need help in building a algaritmo for a code. I'm wondering on how to make a code in C # that checks whether an object (a cube) is on a platform. Like in some games where the player must push a box up a button so that it is pressed ... Does anyone have any idea? Thank you so much!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Easiest way I can think of is to set a collider (marked as a trigger) on the platform. Then you can either do something in the OnTriggerStay and related methods, or in your code, directly test whether it's on the platform by calling something like Physics.CheckSphere.

    HTH,
    - Joe
     
    niick555 likes this.
  3. niick555

    niick555

    Joined:
    Sep 19, 2014
    Posts:
    11
    I understand, thanks! But my idea is to put a quick animation on the platform, lowering and raising it if you have something on top or not. So I put this animation within the OnTriggerStay?
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,848
    Yes, that should work.
     
    niick555 likes this.
  5. niick555

    niick555

    Joined:
    Sep 19, 2014
    Posts:
    11
    I'm getting to do, but it has a problem ... I've never used OnTriggerStay, and thought he would be fired just as the box was above the platform. However this does not occur. Once it is activated, it disappears and does not return ... Will some other way to leave it turned on only while with the box on top?