Beispiel #1
0
    public void DropObject()
    {
        isHoldingObject = false;
        if (currentHeldObject == null)
        {
            return;
        }

        currentHeldObject.GetComponent <Rigidbody>().drag = _prevObjectDrag;
        currentHeldObject = null;
    }
Beispiel #2
0
    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);
        }
    }
Beispiel #3
0
    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());
    }
Beispiel #4
0
    /// <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);
    }