public void DropObject() { isHoldingObject = false; if (currentHeldObject == null) { return; } currentHeldObject.GetComponent <Rigidbody>().drag = _prevObjectDrag; currentHeldObject = null; }
private void OnMouseUp() { plucking = false; endVec = Camera.main.ScreenToWorldPoint(Input.mousePosition); float distance = Vector2.Distance(startVec, endVec); if (Mathf.Abs(distance) >= minDistance) { parent.GetComponent <FoodObject>().Pluck(index); Destroy(gameObject); } }
public void PickUpObject(FoodObject food) { if (currentHeldObject != null) { if (currentHeldObject == food) { return; // already holding this food } else { DropObject(); // drop whatever was being held before } } currentHeldObject = food; _prevObjectDrag = food.GetComponent <Rigidbody>().drag; food.GetComponent <Rigidbody>().drag = 10f; // stop it from osciliating when being picked up _heldFaceDirection = GetClosestFacePosition(food.transform.position); _holdDistance = 0.3f; StartCoroutine(PickUpObjectCoroutine()); }
/// <summary> /// Called by the animator when we are ready to spawn food /// </summary> public void AnimatorSpawnFood() { if (_foodSpawnQueue.Count == 0 || !isOpen || !_isFiring) { return; } UpdateAnimatorSpeed(); FoodSpawnDefinition food = _foodSpawnQueue.Dequeue(); FoodObject newFood = Instantiate(foodPrefab.gameObject).GetComponent <FoodObject>(); newFood.transform.position = spawnPoint.position; newFood.GetComponent <Rigidbody>().AddForce(spawnPoint.forward * spawnForce * (Random.value + 1f), ForceMode.Impulse); newFood.spawner = this; newFood.SetColor(food.color); foodInScene.Add(newFood); }