Ejemplo n.º 1
0
    public CrankGatherer GetNearestCrank(Vector3 position, float range)
    {
        CrankGatherer[] cranks = FindObjectsOfType <CrankGatherer>();

        if (cranks == null)
        {
            return(null);
        }

        CrankGatherer nearestCrank    = null;
        float         nearestDistance = float.PositiveInfinity;

        foreach (CrankGatherer crank in cranks)
        {
            float distance = Vector2.Distance(crank.transform.position, position);

            if (distance < nearestDistance)
            {
                nearestCrank    = crank;
                nearestDistance = distance;
            }
        }

        //  Only return if it's in range
        return((nearestDistance <= range) ? nearestCrank : null);
    }
    void AttemptCrank() {
        CrankGatherer nearest = GameManager.instance.GetNearestCrank(this.gameObject.transform.position, 1.0f);

        if (nearest == null)
        {
            //  TODO: Other stuff here, like start a shrug animation?
            return;
        }

        nearest.IncreaseCrankTurn();
    }