Search Unity

A Stupid Question About Collision and Picking Up and Dropping Items

Discussion in 'Scripting' started by artistshc, Dec 2, 2015.

  1. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    70
    Hi all. I feel stupid even asking it, but I'm having trouble figuring it out (maybe because I am very sick right now). Here I go anyway...


    It is a dollhouse game...

    When the character takes his spatula and picks up food with it, and then drops it on the plate, this works fine. But if I add to script that I want the spoon to pick up the food again when spatula is over the food, then it picks up the food all over again. Do you have any suggestions? I know this is glaringly simple, but again, my brain is foggy from medicines and being sick. Thank you!

    I have this script on the plate, as well as pan

    Code (CSharp):
    1. SpriteRenderer sr;
    2.     public Sprite spatula;
    3.     public Sprite woodenSpoon;
    4.     public Sprite woodenSpoonEgg;
    5.     public Sprite spatulaEgg;
    6.     //YELLOW
    7.     public Sprite spatulaYellow;
    8.     public Sprite woodenSpoonYellow;
    9.     public Sprite spatulaYellowNoodles;
    10.     public Sprite woodenSpoonYellowNoodles;
    11.     //BLUE
    12.     public Sprite spatulaBlue;
    13.     public Sprite woodenSpoonBlue;
    14.     public Sprite spatulaBlueNoodles;
    15.     public Sprite woodenSpoonBlueNoodles;
    16.     //PURPLE
    17.     public Sprite spatulaPurple;
    18.     public Sprite woodenSpoonPurple;
    19.     public Sprite spatulaPurpleNoodles;
    20.     public Sprite woodenSpoonPurpleNoodles;
    21.     //GREEN
    22.     public Sprite spatulaGreen;
    23.     public Sprite woodenSpoonGreen;
    24.     public Sprite spatulaGreenNoodles;
    25.     public Sprite woodenSpoonGreenNoodles;
    26.     //ORANGE
    27.     public Sprite spatulaOrange;
    28.     public Sprite woodenSpoonOrange;
    29.     public Sprite spatulaOrangeNoodles;
    30.     public Sprite woodenSpoonOrangeNoodles;
    31.     //RED
    32.     public Sprite spatulaRed;
    33.     public Sprite woodenSpoonRed;
    34.     public Sprite spatulaRedNoodles;
    35.     public Sprite woodenSpoonRedNoodles;
    36.     //BROWN
    37.     public Sprite spatulaBrown;
    38.     public Sprite woodenSpoonBrown;
    39.     public Sprite spatulaBrownNoodles;
    40.     public Sprite woodenSpoonBrownNoodles;
    41.     //RAINBOW
    42.     public Sprite spatulaRainbow;
    43.     public Sprite woodenSpoonRainbow;
    44.     public Sprite spatulaRainbowNoodles;
    45.     public Sprite woodenSpoonRainbowNoodles;
    46.     //NOODLES
    47.     public Sprite spatulaNoodles;
    48.     public Sprite woodenSpoonNoodles;
    49.     //CHEESE NOODLES
    50.     public Sprite spatulaCheeseNoodles;
    51.     public Sprite woodenSpoonCheeseNoodles;
    52.     //CEREAL
    53.     public Sprite spatulaCereal;
    54.     public Sprite woodenSpoonCereal;
    55.     public Sprite plate;
    56.     //spills to go on plate
    57.     public Transform spillYellow;
    58.     public Transform spillBlue;
    59.     public Transform spillGreen;
    60.     public Transform spillOrange;
    61.     public Transform spillRed;
    62.     public Transform spillBrown;
    63.     public Transform spillRainbow;
    64.     public Transform spillPurple;
    65.     public Transform spillYellowNoodles;
    66.     public Transform spillBlueNoodles;
    67.     public Transform spillGreenNoodles;
    68.     public Transform spillOrangeNoodles;
    69.     public Transform spillRedNoodles;
    70.     public Transform spillBrownNoodles;
    71.     public Transform spillRainbowNoodles;
    72.     public Transform spillPurpleNoodles;
    73.     public Transform spillCereal;
    74.     public Transform spillNoodles;
    75.     public Transform spillEgg;
    76.  
    77.     //variable to check if collided
    78.     bool collided;
    79.     //where to spawn the plate spills
    80.     public Transform plateSpawn;
    81.     bool isInCabinet;
    82.     //find out if cereal is in a drawer or cupboard
    83.     public ItemTracker itemTracker;
    84.     //is the mouse button down
    85.     bool clicked = false;
    86.  
    87.     // Use this for initialization
    88.     void Start () {
    89.         sr = GetComponent<SpriteRenderer>();
    90.         //set default sprite to normal plate
    91.         sr.sprite = plate;
    92.         gameObject.transform.rotation = Quaternion.identity;
    93.         //gameObject.GetComponent<ParticleSystemRenderer> ().sortingLayerName = "Top";
    94.         itemTracker = FindObjectOfType <ItemTracker>();
    95.        
    96.     }
    97.  
    98.     void Update(){
    99.         //find out if this item is in a cabinet or a drawer
    100.         if (itemTracker.itemsInBox.Contains (gameObject)) {
    101.            
    102.             //yes...it is in a drawer or cabinet
    103.             isInCabinet = true;
    104.            
    105.         } else {
    106.             //nope...not in a cabinet or drawer
    107.             isInCabinet = false;
    108.         }
    109.     }
    110.     void OnMouseDown(){
    111.        
    112.         clicked = true;
    113.     }
    114.    
    115.     void OnMouseUp(){
    116.        
    117.         clicked = false;
    118.     }
    119.  
    120.    
    121.     IEnumerator OnTriggerEnter2D (Collider2D other) {
    122.  
    123.         if (isInCabinet == false) {
    124.  
    125.             if ((other.gameObject.tag == "Spill") || (other.gameObject.tag == "Pickable")) {
    126.                 if (clicked == false) {
    127.                     //parent the object to the pot
    128.                     other.transform.parent = this.transform;
    129.                     other.transform.gameObject.GetComponent<SpriteRenderer> ().sortingLayerName = "Toppest";
    130.                     other.transform.gameObject.GetComponent<Renderer> ().sortingOrder = 350;
    131.                 }
    132.                
    133.             }
    134.  
    135.             //MAKE SURE THE OTHER ITEM (SPOON OR SPATULA) IS ON TOP
    136.             other.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Toppest";
    137.             other.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    138.  
    139.             //SPATULAS//
    140.  
    141.             //EGG SPATULA//
    142.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaEgg) {
    143.                 //then collided is true
    144.                 collided = true;
    145.                 //wait for 1 seconds and if still collided then...
    146.                 yield return new WaitForSeconds (1);
    147.                 if (collided) {
    148.                     //Instantiate Egg on the Plate
    149.                     Instantiate (spillEgg, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    150.                     //make it so the spill is on top of the plate
    151.                     spillEgg.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    152.                     spillEgg.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    153.                    
    154.                     //empty the spatula
    155.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    156.                 }
    157.             }
    158.  
    159.             //YELLOW SPATULA//
    160.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaYellow) {
    161.                 //then collided is true
    162.                 collided = true;
    163.                 //wait for 1 seconds and if still collided then...
    164.                 yield return new WaitForSeconds (1);
    165.                 if (collided) {
    166.                     //Instantiate Cereal on the Plate
    167.                     Instantiate (spillYellowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    168.                     //make it so the spill is on top of the plate
    169.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    170.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    171.  
    172.                     //empty the spatula
    173.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    174.                 }
    175.             }
    176.  
    177.             //BLUE SPATULA//
    178.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaBlue) {
    179.                 //then collided is true
    180.                 collided = true;
    181.                 //wait for 1 seconds and if still collided then...
    182.                 yield return new WaitForSeconds (1);
    183.                 if (collided) {
    184.                     //Instantiate Cereal on the Plate
    185.                     Instantiate (spillBlueNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    186.                     //make it so the spill is on top of the plate
    187.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    188.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    189.                     //empty the spatula
    190.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    191.                 }
    192.             }
    193.  
    194.             //PURPLE SPATULA//
    195.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaPurple) {
    196.                 //then collided is true
    197.                 collided = true;
    198.                 //wait for 1 seconds and if still collided then...
    199.                 yield return new WaitForSeconds (1);
    200.                 if (collided) {
    201.                     //Instantiate Cereal on the Plate
    202.                     Instantiate (spillPurpleNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    203.                     //make it so the spill is on top of the plate
    204.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    205.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    206.                     //empty the spatula
    207.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    208.                 }
    209.             }
    210.  
    211.             //GREEN SPATULA//
    212.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaGreen) {
    213.                 //then collided is true
    214.                 collided = true;
    215.                 //wait for 1 seconds and if still collided then...
    216.                 yield return new WaitForSeconds (1);
    217.                 if (collided) {
    218.                     //Instantiate Cereal on the Plate
    219.                     Instantiate (spillGreenNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    220.                     //make it so the spill is on top of the plate
    221.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    222.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    223.                     //empty the spatula
    224.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    225.                 }
    226.             }
    227.  
    228.             //ORANGE SPATULA//
    229.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaOrange) {
    230.                 //then collided is true
    231.                 collided = true;
    232.                 //wait for 1 seconds and if still collided then...
    233.                 yield return new WaitForSeconds (1);
    234.                 if (collided) {
    235.                     //Instantiate Cereal on the Plate
    236.                     Instantiate (spillOrangeNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    237.                     //make it so the spill is on top of the plate
    238.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    239.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    240.                     //empty the spatula
    241.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    242.                 }
    243.             }
    244.  
    245.             //RED SPATULA//
    246.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaRed) {
    247.                 //then collided is true
    248.                 collided = true;
    249.                 //wait for 1 seconds and if still collided then...
    250.                 yield return new WaitForSeconds (1);
    251.                 if (collided) {
    252.                     //Instantiate Cereal on the Plate
    253.                     Instantiate (spillRedNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    254.                     //make it so the spill is on top of the plate
    255.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    256.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    257.                     //empty the spatula
    258.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    259.                 }
    260.             }
    261.  
    262.             //BROWN SPATULA//
    263.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaBrown) {
    264.                 //then collided is true
    265.                 collided = true;
    266.                 //wait for 1 seconds and if still collided then...
    267.                 yield return new WaitForSeconds (1);
    268.                 if (collided) {
    269.                     //Instantiate Cereal on the Plate
    270.                     Instantiate (spillBrownNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    271.                     //make it so the spill is on top of the plate
    272.                     spillBrownNoodles.gameObject.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    273.                     spillBrownNoodles.gameObject.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    274.                     //empty the spatula
    275.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    276.                 }
    277.             }
    278.  
    279.             //RAINBOW SPATULA//
    280.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaRainbow) {
    281.                 //then collided is true
    282.                 collided = true;
    283.                 //wait for 1 seconds and if still collided then...
    284.                 yield return new WaitForSeconds (1);
    285.                 if (collided) {
    286.                     //Instantiate Cereal on the Plate
    287.                     Instantiate (spillRainbowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    288.                     //make it so the spill is on top of the plate
    289.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    290.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    291.                     //empty the spatula
    292.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    293.                 }
    294.             }
    295.  
    296.             //NOODLES SPATULA//
    297.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaNoodles) {
    298.                 //then collided is true
    299.                 collided = true;
    300.                 //wait for 1 seconds and if still collided then...
    301.                 yield return new WaitForSeconds (1);
    302.                 if (collided) {
    303.                     //Instantiate Cereal on the Plate
    304.                     Instantiate (spillNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    305.                     //make it so the spill is on top of the plate
    306.                     spillNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    307.                     spillNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    308.                     //empty the spatula
    309.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    310.                 }
    311.             }
    312.  
    313.             //CHEESE NOODLES SPATULA//
    314.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaCheeseNoodles) {
    315.                 //then collided is true
    316.                 collided = true;
    317.                 //wait for 1 seconds and if still collided then...
    318.                 yield return new WaitForSeconds (1);
    319.                 if (collided) {
    320.                     //Instantiate Cereal on the Plate
    321.                     Instantiate (spillOrangeNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    322.                     //make it so the spill is on top of the plate
    323.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    324.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    325.                     //empty the spatula
    326.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    327.                 }
    328.             }
    329.  
    330.             //YELLOW NOODLES SPATULA//
    331.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaYellowNoodles) {
    332.                 //then collided is true
    333.                 collided = true;
    334.                 //wait for 1 seconds and if still collided then...
    335.                 yield return new WaitForSeconds (1);
    336.                 if (collided) {
    337.                     //Instantiate Cereal on the Plate
    338.                     Instantiate (spillYellowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    339.                     //make it so the spill is on top of the plate
    340.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    341.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    342.                     //empty the spatula
    343.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    344.                 }
    345.             }
    346.  
    347.             //BLUE NOODLES SPATULA//
    348.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaBlueNoodles) {
    349.                 //then collided is true
    350.                 collided = true;
    351.                 //wait for 1 seconds and if still collided then...
    352.                 yield return new WaitForSeconds (1);
    353.                 if (collided) {
    354.                     //Instantiate Cereal on the Plate
    355.                     Instantiate (spillBlueNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    356.                     //make it so the spill is on top of the plate
    357.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    358.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    359.                     //empty the spatula
    360.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    361.                 }
    362.             }
    363.  
    364.             //GREEN NOODLES SPATULA//
    365.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaGreenNoodles) {
    366.                 //then collided is true
    367.                 collided = true;
    368.                 //wait for 1 seconds and if still collided then...
    369.                 yield return new WaitForSeconds (1);
    370.                 if (collided) {
    371.                     //Instantiate Cereal on the Plate
    372.                     Instantiate (spillGreenNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    373.                     //make it so the spill is on top of the plate
    374.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    375.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    376.                     //empty the spatula
    377.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    378.                 }
    379.             }
    380.  
    381.             //RED NOODLES SPATULA//
    382.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaRedNoodles) {
    383.                 //then collided is true
    384.                 collided = true;
    385.                 //wait for 1 seconds and if still collided then...
    386.                 yield return new WaitForSeconds (1);
    387.                 if (collided) {
    388.                     //Instantiate Cereal on the Plate
    389.                     Instantiate (spillRedNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    390.                     //make it so the spill is on top of the plate
    391.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    392.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    393.                     //empty the spatula
    394.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    395.                 }
    396.             }
    397.  
    398.             //BROWN NOODLES SPATULA//
    399.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaBrownNoodles) {
    400.                 //then collided is true
    401.                 collided = true;
    402.                 //wait for 1 seconds and if still collided then...
    403.                 yield return new WaitForSeconds (1);
    404.                 if (collided) {
    405.                     //Instantiate Cereal on the Plate
    406.                     Instantiate (spillBrownNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    407.                     //make it so the spill is on top of the plate
    408.                     spillBrownNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    409.                     spillBrownNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    410.                     //empty the spatula
    411.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    412.                 }
    413.             }
    414.  
    415.             //RAINBOW NOODLES SPATULA//
    416.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaRainbowNoodles) {
    417.                 //then collided is true
    418.                 collided = true;
    419.                 //wait for 1 seconds and if still collided then...
    420.                 yield return new WaitForSeconds (1);
    421.                 if (collided) {
    422.                     //Instantiate Cereal on the Plate
    423.                     Instantiate (spillRainbowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    424.                     //make it so the spill is on top of the plate
    425.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    426.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    427.                     //empty the spatula
    428.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    429.                 }
    430.             }
    431.  
    432.             //PURPLE NOODLES SPATULA//
    433.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaPurpleNoodles) {
    434.  
    435.                 //then collided is true
    436.                 collided = true;
    437.                 //wait for 1 seconds and if still collided then...
    438.                 yield return new WaitForSeconds (1);
    439.                 if (collided) {
    440.                     //Instantiate Cereal on the Plate
    441.                     Instantiate (spillPurpleNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    442.                     //make it so the spill is on top of the plate
    443.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    444.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    445.                     //empty the spatula
    446.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    447.                 }
    448.             }
    449.  
    450.             //CEREAL SPATULA//
    451.             if (other.GetComponent<SpriteRenderer>().sprite == spatulaCereal) {
    452.                 //then collided is true
    453.                 collided = true;
    454.                 //wait for 1 seconds and if still collided then...
    455.                 yield return new WaitForSeconds (1);
    456.                 if (collided) {
    457.                     //Instantiate Cereal on the Plate
    458.                     Instantiate (spillCereal, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    459.                     //make it so the spill is on top of the plate
    460.                     spillCereal.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    461.                     spillCereal.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    462.                     //empty the spatula
    463.                     other.GetComponent<SpriteRenderer>().sprite = spatula;
    464.                 }
    465.             }
    466.  
    467.  
    468.             //WOODEN SPOONS//
    469.  
    470.  
    471.             //EGG WOODEN SPOON//
    472.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonEgg) {
    473.                 //then collided is true
    474.                 collided = true;
    475.                 //wait for 1 seconds and if still collided then...
    476.                 yield return new WaitForSeconds (1);
    477.                 if (collided) {
    478.                     //Instantiate Egg on the Plate
    479.                     Instantiate (spillEgg, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    480.                     //make it so the spill is on top of the plate
    481.                     spillEgg.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    482.                     spillEgg.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    483.                    
    484.                     //empty the woodenSpoon
    485.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    486.                 }
    487.             }
    488.  
    489.             //YELLOW WOODEN SPOON//
    490.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonYellow) {
    491.                 //then collided is true
    492.                 collided = true;
    493.                 //wait for 1 seconds and if still collided then...
    494.                 yield return new WaitForSeconds (1);
    495.                 if (collided) {
    496.                     //Instantiate Cereal on the Plate
    497.                     Instantiate (spillYellowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    498.                     //make it so the spill is on top of the plate
    499.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    500.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    501.  
    502.                     //empty the woodenSpoon
    503.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    504.                 }
    505.             }
    506.  
    507.             //BLUE WOODEN SPOON//
    508.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonBlue) {
    509.                 //then collided is true
    510.                 collided = true;
    511.                 //wait for 1 seconds and if still collided then...
    512.                 yield return new WaitForSeconds (1);
    513.                 if (collided) {
    514.                     //Instantiate Cereal on the Plate
    515.                     Instantiate (spillBlueNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    516.                     //make it so the spill is on top of the plate
    517.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    518.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    519.                     //empty the woodenSpoon
    520.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    521.                 }
    522.             }
    523.  
    524.             //PURPLE WOODEN SPOON//
    525.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonPurple) {
    526.                 //then collided is true
    527.                 collided = true;
    528.                 //wait for 1 seconds and if still collided then...
    529.                 yield return new WaitForSeconds (1);
    530.                 if (collided) {
    531.                     //Instantiate Cereal on the Plate
    532.                     Instantiate (spillPurpleNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    533.                     //make it so the spill is on top of the plate
    534.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    535.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    536.                     //empty the woodenSpoon
    537.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    538.                 }
    539.             }
    540.  
    541.             //GREEN WOODEN SPOON//
    542.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonGreen) {
    543.                 //then collided is true
    544.                 collided = true;
    545.                 //wait for 1 seconds and if still collided then...
    546.                 yield return new WaitForSeconds (1);
    547.                 if (collided) {
    548.                     //Instantiate Cereal on the Plate
    549.                     Instantiate (spillGreenNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    550.                     //make it so the spill is on top of the plate
    551.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    552.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    553.                     //empty the woodenSpoon
    554.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    555.                 }
    556.             }
    557.  
    558.             //ORANGE WOODEN SPOON//
    559.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonOrange) {
    560.                 //then collided is true
    561.                 collided = true;
    562.                 //wait for 1 seconds and if still collided then...
    563.                 yield return new WaitForSeconds (1);
    564.                 if (collided) {
    565.                     //Instantiate Cereal on the Plate
    566.                     Instantiate (spillOrangeNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    567.                     //make it so the spill is on top of the plate
    568.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    569.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    570.                     //empty the woodenSpoon
    571.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    572.                 }
    573.             }
    574.  
    575.             //RED WOODEN SPOON//
    576.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonRed) {
    577.                 //then collided is true
    578.                 collided = true;
    579.                 //wait for 1 seconds and if still collided then...
    580.                 yield return new WaitForSeconds (1);
    581.                 if (collided) {
    582.                     //Instantiate Cereal on the Plate
    583.                     Instantiate (spillRedNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    584.                     //make it so the spill is on top of the plate
    585.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    586.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    587.                     //empty the woodenSpoon
    588.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    589.                 }
    590.             }
    591.  
    592.             //BROWN WOODEN SPOON//
    593.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonBrown) {
    594.                 //then collided is true
    595.                 collided = true;
    596.                 //wait for 1 seconds and if still collided then...
    597.                 yield return new WaitForSeconds (1);
    598.                 if (collided) {
    599.                     //Instantiate Cereal on the Plate
    600.                     Instantiate (spillBrownNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    601.                     //make it so the spill is on top of the plate
    602.                     spillBrownNoodles.gameObject.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    603.                     spillBrownNoodles.gameObject.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    604.                     //empty the woodenSpoon
    605.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    606.                 }
    607.             }
    608.  
    609.             //RAINBOW WOODEN SPOON//
    610.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonRainbow) {
    611.                 //then collided is true
    612.                 collided = true;
    613.                 //wait for 1 seconds and if still collided then...
    614.                 yield return new WaitForSeconds (1);
    615.                 if (collided) {
    616.                     //Instantiate Cereal on the Plate
    617.                     Instantiate (spillRainbowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    618.                     //make it so the spill is on top of the plate
    619.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    620.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    621.                     //empty the woodenSpoon
    622.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    623.                 }
    624.             }
    625.  
    626.             //NOODLES WOODEN SPOON//
    627.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonNoodles) {
    628.                 //then collided is true
    629.                 collided = true;
    630.                 //wait for 1 seconds and if still collided then...
    631.                 yield return new WaitForSeconds (1);
    632.                 if (collided) {
    633.                     //Instantiate Cereal on the Plate
    634.                     Instantiate (spillNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    635.                     //make it so the spill is on top of the plate
    636.                     spillNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    637.                     spillNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    638.                     //empty the woodenSpoon
    639.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    640.                 }
    641.             }
    642.  
    643.             //CHEESE NOODLES WOODEN SPOON//
    644.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonOrangeNoodles) {
    645.                 //then collided is true
    646.                 collided = true;
    647.                 //wait for 1 seconds and if still collided then...
    648.                 yield return new WaitForSeconds (1);
    649.                 if (collided) {
    650.                     //Instantiate Cereal on the Plate
    651.                     Instantiate (spillOrangeNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    652.                     //make it so the spill is on top of the plate
    653.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    654.                     spillOrangeNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    655.                     //empty the woodenSpoon
    656.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    657.                 }
    658.             }
    659.  
    660.             //YELLOW NOODLES WOODEN SPOON//
    661.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonYellowNoodles) {
    662.                 //then collided is true
    663.                 collided = true;
    664.                 //wait for 1 seconds and if still collided then...
    665.                 yield return new WaitForSeconds (1);
    666.                 if (collided) {
    667.                     //Instantiate Cereal on the Plate
    668.                     Instantiate (spillYellowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    669.                     //make it so the spill is on top of the plate
    670.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    671.                     spillYellowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    672.                     //empty the woodenSpoon
    673.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    674.                 }
    675.             }
    676.  
    677.             //BLUE NOODLES WOODEN SPOON//
    678.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonBlueNoodles) {
    679.                 //then collided is true
    680.                 collided = true;
    681.                 //wait for 1 seconds and if still collided then...
    682.                 yield return new WaitForSeconds (1);
    683.                 if (collided) {
    684.                     //Instantiate Cereal on the Plate
    685.                     Instantiate (spillBlueNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    686.                     //make it so the spill is on top of the plate
    687.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    688.                     spillBlueNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    689.                     //empty the woodenSpoon
    690.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    691.                 }
    692.             }
    693.  
    694.             //GREEN NOODLES WOODEN SPOON//
    695.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonGreenNoodles) {
    696.                 //then collided is true
    697.                 collided = true;
    698.                 //wait for 1 seconds and if still collided then...
    699.                 yield return new WaitForSeconds (1);
    700.                 if (collided) {
    701.                     //Instantiate Cereal on the Plate
    702.                     Instantiate (spillGreenNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    703.                     //make it so the spill is on top of the plate
    704.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    705.                     spillGreenNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    706.                     //empty the woodenSpoon
    707.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    708.                 }
    709.             }
    710.  
    711.             //RED NOODLES WOODEN SPOON//
    712.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonRedNoodles) {
    713.                 //then collided is true
    714.                 collided = true;
    715.                 //wait for 1 seconds and if still collided then...
    716.                 yield return new WaitForSeconds (1);
    717.                 if (collided) {
    718.                     //Instantiate Cereal on the Plate
    719.                     Instantiate (spillRedNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    720.                     //make it so the spill is on top of the plate
    721.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    722.                     spillRedNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    723.                     //empty the woodenSpoon
    724.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    725.                 }
    726.             }
    727.  
    728.             //BROWN NOODLES WOODEN SPOON//
    729.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonBrownNoodles) {
    730.                 //then collided is true
    731.                 collided = true;
    732.                 //wait for 1 seconds and if still collided then...
    733.                 yield return new WaitForSeconds (1);
    734.                 if (collided) {
    735.                     //Instantiate Cereal on the Plate
    736.                     Instantiate (spillBrownNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    737.                     //make it so the spill is on top of the plate
    738.                     spillBrownNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    739.                     spillBrownNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    740.                     //empty the woodenSpoon
    741.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    742.                 }
    743.             }
    744.  
    745.             //RAINBOW NOODLES WOODEN SPOON//
    746.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonRainbowNoodles) {
    747.                 //then collided is true
    748.                 collided = true;
    749.                 //wait for 1 seconds and if still collided then...
    750.                 yield return new WaitForSeconds (1);
    751.                 if (collided) {
    752.                     //Instantiate Cereal on the Plate
    753.                     Instantiate (spillRainbowNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    754.                     //make it so the spill is on top of the plate
    755.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    756.                     spillRainbowNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    757.                     //empty the woodenSpoon
    758.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    759.                 }
    760.             }
    761.  
    762.             //PURPLE NOODLES WOODEN SPOON//
    763.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonPurpleNoodles) {
    764.                 //then collided is true
    765.                 collided = true;
    766.                 //wait for 1 seconds and if still collided then...
    767.                 yield return new WaitForSeconds (1);
    768.                 if (collided) {
    769.                     //Instantiate Cereal on the Plate
    770.                     Instantiate (spillPurpleNoodles, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    771.                     //make it so the spill is on top of the plate
    772.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    773.                     spillPurpleNoodles.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    774.                     //empty the woodenSpoon
    775.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    776.                 }
    777.             }
    778.  
    779.             //CEREAL WOODEN SPOON//
    780.             if (other.GetComponent<SpriteRenderer>().sprite == woodenSpoonCereal) {
    781.                 //then collided is true
    782.                 collided = true;
    783.                 //wait for 1 seconds and if still collided then...
    784.                 yield return new WaitForSeconds (1);
    785.                 if (collided) {
    786.                     //Instantiate Cereal on the Plate
    787.                     Instantiate (spillCereal, new Vector3 (plateSpawn.transform.position.x, plateSpawn.transform.position.y, 0), Quaternion.identity);
    788.                     //make it so the spill is on top of the plate
    789.                     spillCereal.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    790.                     spillCereal.gameObject.GetComponent<SpriteRenderer>().sortingOrder = 75;
    791.                     //empty the woodenSpoon
    792.                     other.GetComponent<SpriteRenderer>().sprite = woodenSpoon;
    793.                 }
    794.             }
    795.  
    796.  
    797.  
    798.  
    799.  
    800.  
    801.  
    802.  
    803.         }//end if (isInCabinet == false)
    804.     }
    805.  
    806.     //DROPPING ITEM
    807.     void OnTriggerExit2D (Collider2D other) {
    808.         if((other.gameObject.tag == "Spill") || (other.gameObject.tag == "Pickable")){
    809.            
    810.             //make it so that the object is NOT parented to the character any more
    811.             other.transform.parent = null;
    812.             other.transform.GetComponent<SpriteRenderer>().sortingLayerName = "Default";
    813.         }
    814.        
    815.         collided = false;
    816.        
    817.  
    818.     }
     
unityunity