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

Question can somebody help me?

Discussion in 'Getting Started' started by Envokbalazs, Sep 8, 2023.

  1. Envokbalazs

    Envokbalazs

    Joined:
    Jan 27, 2023
    Posts:
    1
    I have a 2D game in Unity which contains 2 ground objects, one above the other and that game also has a character. I want the character to be able to fly from one to the other, so if I press a UI button the character will fly down and if I press another UI button the character will fly up. Both of the grounds have box colliders, and I want to have the down UI button only accessible when I'm at the upper ground and the up UI button when I'm at the lower ground. so basically the character can go through the upper ground if I press the down UI button and when I'm at the lower ground the character can fly up to the upper ground and when the character is above the upper ground the box collider of the upper ground reappers.
     
  2. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    what did you try already? can you share some code?
     
  3. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    437
    1. If a character is grounded (you must know it touched a floor) and you press a button to lower ground you start a function JumpOff.
    2. Function JumpOff needs to turn on Is Trigger on Collider2D of the character so he passes the floor.
    3. Now you need to know when the character stops passing the floor. You can use OnTriggerExit2D to turn off Is Trigger.
     
  4. Mattsgonnamine24

    Mattsgonnamine24

    Joined:
    Sep 11, 2023
    Posts:
    1
    Use circleCasts to see if your character is touching the ground, I'm relatively new to unity as well but I understand that if they overlap with something on the correct layer than they will constantly send out a trigger
     
  5. AngryProgrammer

    AngryProgrammer

    Joined:
    Jun 4, 2019
    Posts:
    437
    The Collider2D ignore layers. Objects dont have to be on a same layer. If you turn on Is Trigger it will become like transparent and will pass everything.