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
  4. Dismiss Notice

Question URGENT HELP NEEDED

Discussion in '2D' started by lolisuck, Aug 6, 2020.

  1. lolisuck

    lolisuck

    Joined:
    Aug 6, 2020
    Posts:
    5
    I Currently Participating In A Game Jam And I Need Help Creating Sort Of A Pressure Pad Where If You Put A Crate On It Or If You Stand On It The Button Goes Down And A Door Opens Or Somthing And Once You Get Off Or Once The Crate Gets Off The Door Closes And The Button Goes Back Up, I'm Using 2D Btw
    Heres The Code I Used For The Button When Its Not Pressed(I Made 2 GameObjects And Put Then Active And UnActive When Player Gets Off Or Crate Gets Off):
    Code (CSharp):
    1.   public GameObject buttonwhenPressed;
    2.    
    3.     void Start()
    4.     {
    5.        
    6.     }
    7.     public void OnCollisionEnter2D(Collision2D collision)
    8.     {
    9.         if(collision.gameObject.tag == "Crate")
    10.         {
    11.  
    12.             buttonwhenPressed.SetActive(true);
    13.  
    14.             gameObject.SetActive(false);
    15.  
    16.  
    17.  
    18.  
    19.  
    20.  
    21.  
    22.  
    23.  
    24.  
    25.  
    26.  
    27.  
    28.         }
    29.        
    30.  
    31.         if (collision.gameObject.tag == "Player")
    32.         {
    33.  
    34.             buttonwhenPressed.SetActive(true);
    35.  
    36.             gameObject.SetActive(false);
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43.  
    44.  
    45.  
    46.  
    47.  
    48.  
    49.  
    50.         }
    51.  
    52.  
    53.  
    54.     }
    55.     // Update is called once per frame
    56.     void Update()
    57.     {
    58.        
    59.     }
    Heres The Code For The Button When Pressed :
    Code (CSharp):
    1.  public GameObject whenbuttonnotPressed;
    2.    
    3.    
    4.    
    5.    
    6.     // Start is called before the first frame update
    7.     void Start()
    8.     {
    9.        
    10.     }
    11.     public void OnCollisionExit2D(Collision2D collision)
    12.     {
    13.  
    14.  
    15.  
    16.         whenbuttonnotPressed.SetActive(true);
    17.        
    18.        
    19.         gameObject.SetActive(false);
    20.     }
    21.     // Update is called once per frame
    22.     void Update()
    23.     {
    24.        
    25.     }
    Please Help And Ask Q If Your Confused
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    you didnt say what wasnt working
     
  3. lolisuck

    lolisuck

    Joined:
    Aug 6, 2020
    Posts:
    5
    Everthing
     
  4. lolisuck

    lolisuck

    Joined:
    Aug 6, 2020
    Posts:
    5
    I Just Need To Now How To Do A Button
     
  5. lolisuck

    lolisuck

    Joined:
    Aug 6, 2020
    Posts:
    5
    Nah Like A Pressure Pad My Bad My G
     
  6. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481
  7. lolisuck

    lolisuck

    Joined:
    Aug 6, 2020
    Posts:
    5