void OnTriggerEnter2D(Collider2D col) { //Collect Vegitables if (col.gameObject.GetComponent <Vegitable>()) { Vegitable _vegitable = col.gameObject.GetComponent <Vegitable>(); if (collectedVegies.Count >= 2) { return; } foreach (VegitableType veg in collectedVegies) { if (veg == _vegitable.vegitableType) { return; } } collectedVegies.Add(_vegitable.vegitableType); ShowCollectedVegText(); } if (col.gameObject.GetComponent <ChoppingBoard>()) { ChoppingBoard _choppingBoard = col.gameObject.GetComponent <ChoppingBoard>(); if (collectedVegies.Count > 0) { //Chop Vegitables _choppingBoard.ChopVegitable(collectedVegies[0], this); collectedVegies.RemoveAt(0); transform.position += new Vector3(0, 1, 0); ShowCollectedVegText(); } else { //collect Chopped Vegitables choppedVegitables.Clear(); choppedVegitables = new List <VegitableType>(_choppingBoard.CollectChoppedVegitables()); _choppingBoard.choppedVegitables.Clear(); vegCollectedText.text = ""; for (int i = 0; i < choppedVegitables.Count; i++) { vegCollectedText.text = vegCollectedText.text + " " + choppedVegitables[i].ToString(); } vegCollectedText.color = Color.red; } } //Plate store one veg item if its empty else collect item from plate if (col.gameObject.GetComponent <Plate>()) { VegitableType plateVeg = col.gameObject.GetComponent <Plate>().CollectFromPlate(); if (plateVeg == 0 && collectedVegies.Count > 0) { col.gameObject.GetComponent <Plate>().OnPlate(collectedVegies[0]); collectedVegies.RemoveAt(0); } else if (plateVeg != 0) { foreach (VegitableType veg in collectedVegies) { if (veg == plateVeg) { return; } } collectedVegies.Add(plateVeg); } ShowCollectedVegText(); } //Trash if (col.gameObject.layer == 8) { if (collectedVegies.Count > 0) { collectedVegies.RemoveAt(0); } else { if (choppedVegitables.Count > 0) { choppedVegitables.RemoveAt(0); } } ShowCollectedVegText(); } //Serve Salad to Customer if (col.gameObject.GetComponent <Customer>()) { Customer _customer = col.gameObject.GetComponent <Customer>(); if (choppedVegitables.Count == _customer.saladRecipe.Count) { for (int i = 0; i < choppedVegitables.Count; i++) { if (choppedVegitables[i] != _customer.saladRecipe[i]) { goto failed; } } _customer.CustomerServedSuccessfully(); AddScore(_customer.scoreValue); if (_customer.progressBar.fillAmount < .7f) { isReadyForPickup = true; GamePlayManager.Instance.InitiatePickup(); } choppedVegitables.Clear(); ShowCollectedVegText(); return; } else { goto failed; } failed: _customer.DecreaseWaitingTimeFaster(); AddScore(-5); choppedVegitables.Clear(); ShowCollectedVegText(); } if (col.gameObject.GetComponent <Pickups>() && isReadyForPickup) { Pickups pickups = col.gameObject.GetComponent <Pickups>(); OnPickupCollect(pickups.pickupType); pickups.HidePickup(); } }
public static void xMain() { #region Type System (Value Types/Reference Types, Memory Allocation of value types and ref types, Methods,Type Casting //Value types:- all those types which are primitive types or system generated types. //1-All structs //2-Value types creates on Stack in memory(RAM) //3-Example all those types which are not human made. //4-It hold the values only. uint ui = 10; int i = 0; // Int32 short s = 1; //Int16 long l = 10; //Int64 byte b = 1; double d = 1.6; float f = 1.34f; bool b_bool = true; char c = 'a'; char c1 = 'b'; //Reference Type:- //Address to the object //Object Vitz1999Standard vitz = new Vitz1999Standard(); Console.WriteLine(vitz.dimensions); Console.WriteLine(vitz.engine); //All references create on heap //User defined Types/Classes string str = "1dkashdkash1.45true"; Vegitable v = GiveMeVegitable(100, new Bike()); int subResult = Subtract(1, 2); //Type Casting int result = (int)(3.5 - 1.2); //Explicit type casting double dResult = 5 - 2; //Implicit Type Casting float fResult = 1.5f - 1; //Implicit Type Casting int iResult = (int)(1.5f - (float)3.2d); //Explicit type casting #endregion // Copy by Value (Value Type) int x = 10; int y = x; y = 12; Console.WriteLine($"{x}, {y}");// 10,12 // Copy by Reference (Reference Type) //200 //100 A obj1 = new A() { a = 10 }; //300 = //200 A obj2 = obj1; obj2.a = 12; Console.WriteLine($"{obj1.a}, {obj2.a}");//12,12 Console.WriteLine("Hello world"); //Arithmatic Operations:- //pre-fix int p1 = 0; // ++ == increment by one, => x=x+1, x+=1 Console.WriteLine(++p1); // p1=1, print(1) Console.WriteLine(p1++); // p1=2, print(1) p1 = 0; int val = p1++ + ++p1; p1 += 2; /*equals*/ p1 = p1 + 2; p1 -= 4; /*equals*/ p1 = p1 - 4; --p1; p1--; //Concatination Console.WriteLine("aamir" + "akhtar"); //Reference type casting C objC1 = new C(); P objB1 = (P)objC1; // Valid bcz Child can be type casted to parent but not vice versa P objB2 = new P(); //C objC2 = (C)objB2; //Invalid bcz Parent cannot be type casted to child //String Formatting //1-Parameterized Console.WriteLine("x={0}, y={1}", x, y); //2-Dollar Console.WriteLine($"x={x}, y={y}"); Console.WriteLine("**aamir\nakhtar**"); Console.WriteLine("**aamir\takhtar**"); //BioData objBioData1 = new BioData();//Default Constructor //BioData objBioData2 = new BioData(30);//Overloaded Constructor BioData farasatBioData = new BioData() { FirstName = "Farasat", LastName = "Hussain", Age = 21, Address = "Austria", Gender = "Male", Profession = "Student" }; BioData farasatBioDataCopy = new BioData(farasatBioData); BioData objBioData3 = new BioData(); //Static property BioData.FathersName = "Donald"; //Non-static properties BioData b1 = new BioData(); b1.FirstName = "noman"; b1.LastName = "Aqeel"; BioData.GetFullName(b1.FirstName, b1.LastName); BioData b2 = new BioData(); b2.FirstName = "aamir"; b2.LastName = "akhtar"; BioData.GetFullName(b2.FirstName, b2.LastName); BioData b3 = new BioData(); b3.FirstName = "farast"; b3.LastName = "hussain"; BioData.GetFullName(b3.FirstName, b3.LastName); b1.GetBio(); BioData.PrintFathersName(); Console.ReadLine(); }