void blendItem(BlendItem blenditem) { if (blenditem.fillAmmount + current_ammount <= max_fill) { print(mixer.name); mixer.addColor(blenditem.blendedColor, blenditem.blendIntensity, blenditem.fillAmmount * timePerPercentage); current_ammount += blenditem.fillAmmount; fillSprite.transform.localPosition = new Vector3(0, (current_ammount * (max_y_coordinates - min_y_coordinates) / max_fill) + min_y_coordinates, 0); Destroy(blenditem.gameObject); } else { blenditem.GetComponent <Rigidbody2D>().AddForce(new Vector2(0, 1000)); } }
void OnTriggerEnter2D(Collider2D col) { BlendItem blendItem = col.GetComponent <BlendItem>(); if (blendItem != null && blendItem.itemType == ItemType.MONEY) { int numItemsValue = col.GetComponent <MoneyItem>().numItemsValue; BlendItem[] itemsToSpawn; switch (deliveryType) { case DeliveryType.GROCERIES: if (Utils.ThrowDice(weedChance)) { itemsToSpawn = Utils.CreateFilledArray(numItemsValue, GameContoller.INSTANCE.weed); } else { itemsToSpawn = Utils.GetRandomArray(numItemsValue, GameContoller.INSTANCE.groceries); } break; case DeliveryType.MILK: itemsToSpawn = Utils.CreateFilledArray(numItemsValue, GameContoller.INSTANCE.milk); break; default: throw new ArgumentOutOfRangeException(); } foreach (BlendItem item in itemsToSpawn) { Rigidbody2D spawnedItem = Instantiate(item.gameObject, transform.position, Quaternion.identity).GetComponent <Rigidbody2D>(); spawnedItem.AddForce(Utils.RandomVector(minSpawnForce, maxSpawnForce)); } GameObject.Find("rightHand").GetComponent <handController>().Release(); Destroy(blendItem.gameObject); } }
public void OnTriggerEnter2D(Collider2D collision) { print("Hei" + collision.name); BlendItem item = collision.GetComponent <BlendItem>(); if (collision.transform.parent != null) { item = collision.GetComponentInParent <BlendItem>(); } if (item != null) { blendItem(item); hand.Release(); } else if (collision.tag == "Lid" && timeLidded + 2.5f < Time.time && current_ammount != 0) { lidPrefab = collision.gameObject; lidPrefab.SetActive(false); putOnLid(); hand.Release(); } }
public void OnTriggerStay2D(Collider2D collision) { BlendItem item = collision.GetComponent <BlendItem>(); if (collision.transform.parent != null) { item = collision.GetComponentInParent <BlendItem>(); } if (item != null || collision.tag == "Lid") { if (Input.GetMouseButtonDown(0)) { GetComponent <SpriteRenderer>().sprite = sprite2; rightClone.GetComponent <SpriteRenderer>().sprite = sprite2; leftClone.GetComponent <SpriteRenderer>().sprite = sprite2; rb = collision.GetComponent <Rigidbody2D>(); if (collision.transform.parent != null) { rb = collision.GetComponentInParent <Rigidbody2D>(); } } } }