Search Unity

Items Get Locked In Place - Trying to Hide Object Behind Door

Discussion in 'Scripting' started by artistshc, May 12, 2015.

  1. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    79
    So I have a kitchen cabinet that can open and close. I got it to work where you are able to place items in it and close the door and the items are hidden. But about 20% of the time the items get locked in place and you can't move them unless you turn the item on and off in the inspector or you drag another item behind it. So for example...if the apple stops being able to move around, I can drag the banana behind it and then I can move the apple again. It is very odd. Here are the screenshots...

    The 3rd screenshot is just a pic of the rigidbody that is on the fruit.

    I have this code on the open door

    Code (CSharp):
    1. //When you click on this object...
    2.     void OnMouseDown() {
    3.  
    4.         //set the orange door to be inactive
    5.         CabinetTopOrange.SetActive(false);
    6.  
    7.  
    8.     }
    And I have this code on the closed door

    Code (CSharp):
    1. //When you click on this object...
    2.     void OnMouseDown() {
    3.  
    4.         //Find GameObject and disable it
    5.         CabinetTopOrange.SetActive(true);
    6.        
    7.     }
    And have this code on the inside of the cabinet, which I call contents. It is simply a box collider 2d with trigger.

    Code (CSharp):
    1. //CHARACTER PICKING UP ITEM
    2.     void OnTriggerEnter2D(Collider2D other) {
    3.        
    4.         if (other.gameObject.tag == "Pickable") {
    5.             //parent pickable item to the Contents transform
    6.             other.transform.parent = this.transform;
    7.  
    8.         }
    9.     }
    10.    
    11.     //DROPPING ITEM
    12.     void OnTriggerExit2D (Collider2D other) {
    13.         if(other.gameObject.tag == "Pickable"){
    14.            
    15.             //make it so that the object is NOT parented to the character any more
    16.             other.transform.parent = null;
    17.  
    18.            
    19.         }
    20.     }
    21.  
    22.     void onMouseDown(){
    23.  
    24.  
    25.         Content.SetActive (true);
    26.     }
    Please help ... it has been driving me mad for 3 days now. Thank you!
    Rachel
     

    Attached Files:

  2. IO-Fox

    IO-Fox

    Joined:
    Jul 14, 2014
    Posts:
    86
    Perhaps it's because of parenting. Are the item rigidbodies? Do you mind uploading the scene?
     
  3. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    79
    Oh Thank you for taking a look!!!! How should I upload it, when I tried to here it says that it is wrong file type to upload. Thank you!!!!
     
    Deleted User likes this.
  4. IO-Fox

    IO-Fox

    Joined:
    Jul 14, 2014
    Posts:
    86
    Just provide a dropbox link :)
     
    artistshc likes this.
  5. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    79
    Ooops...didn't see your comment. I just uploaded it to my server.
     
  6. IO-Fox

    IO-Fox

    Joined:
    Jul 14, 2014
    Posts:
    86
    I'll give it a go and let you know what I turn up :)
     
  7. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    79
    Thank you soooo much!
     
  8. Stef_Morojna

    Stef_Morojna

    Joined:
    Apr 15, 2015
    Posts:
    289
    Btw that art style for the game looks really cute.
     
  9. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    79
    Thank you so much Stef!!! Its going to be a dollhouse game for little kids.