示例#1
0
    public GameObject getNearestSnappable()
    {
        GameObject[] snapToObjects   = GameObject.FindGameObjectsWithTag("snapingredient");
        GameObject   nearestObject   = null;
        double       largestDistance = double.PositiveInfinity;

        //get the nearest snappable object within its threshold
        for (int i = 0; i < snapToObjects.Length; i++)
        {
            GameObject       g      = snapToObjects[i];
            AcceptIngredient gSnap  = g.GetComponent <AcceptIngredient>();
            Vector2          newPos = gameObject.transform.position;

            //check this.threshold and the other object's threshold to find the closest
            float d = GetDistance(newPos, g.transform.position);

            //various error checking
            if ((d < threshold || d < g.GetComponent <AcceptIngredient>().threshold) &&
                d < largestDistance &&
                (!this.snapExclusive || this.snapToNameTag.Contains(g.name) || this.snapToNameTag.Contains(g.tag)) &&
                g != gameObject &&
                g != null &&
                (!gSnap.exclusive || gSnap.acceptNameTag.Contains(this.gameObject.name) || gSnap.acceptNameTag.Contains(this.tag)) &&
                (g.transform.parent != null && g.transform.parent.name != this.name))
            {
                nearestObject = g;
            }
        }
        return(nearestObject);
    }
 void Start()
 {
     foreach (Transform child in this.transform)
     {
         if (child.tag == "snapingredient")
         {
             placedIngredients = child.gameObject.GetComponent <AcceptIngredient>();
         }
     }
     dragIngredients = this.GetComponent <DragIngredient>();
 }
示例#3
0
    // Use this for initialization
    void Start()
    {
        espresso = 0;

        cupDragScript = GetComponent <DragObject>();
        foreach (Transform child in transform)
        {
            if (child.name == "ingredient-snapper")
            {
                ingredients = child.GetComponent <AcceptIngredient>();
                break;
            }
        }
        cupCollider         = GetComponent <BoxCollider2D>();
        steamSprite         = steamAnimation.GetComponent <SpriteRenderer>();
        steamSprite.enabled = false;

        drink      = new Drink();
        drink.size = this.size;
    }