private void resetCurrBin()
 {
     if (currBin != null)
     {
         //it was last at this bin, so this bin is now free
         binBehavior currBinScript = currBin.GetComponent <binBehavior>();
         currBinScript.activated = false;
         Debug.Log("this bin is no longer holding anything");
     }
     currBin = null;
 }
    public void released(Vector3 mousePos)
    {
        //loop through all the bins, find the closest bin, if closest <= binDist,
        //translate pickup to that binPos and check if bin is correct bin, otherwise translate to origpos
        Debug.Log("I was released!");
        float     mindist = Mathf.Infinity;
        float     distance;
        Transform closestBin = transform;

        foreach (Transform bin in bins.transform)
        {
            binBehavior binScript = bin.gameObject.GetComponent <binBehavior> ();
            if (!binScript.isOccupied() && binScript.house.GetComponent <houseBehavior>().available)
            {
                distance = Vector2.Distance(transform.position, bin.position);
                Debug.Log(distance);
                if (distance < mindist)
                {
                    mindist    = distance;
                    closestBin = bin;
                }
            }
        }
        if (mindist < binDist)
        {
            Debug.Log("snapped to bin!");
            transform.position = closestBin.transform.position;
            resetCurrBin();
            closestBin.gameObject.GetComponent <binBehavior> ().checkActivation(attrs);
            currBin = closestBin.gameObject;
        }
        else
        {
            Debug.Log("snapped to oldPos, wasnt close enough to a vacant bin!");
            if (currBin == null)
            {
                transform.position = origPos;
            }
            else
            {
                transform.position = currBin.transform.position;
                currBin.GetComponent <binBehavior> ().checkActivation(attrs);
            }
        }
        heldByMouse = false;
    }
Example #3
0
 // Use this for initialization
 void Awake()
 {
     props  = GetComponentInParent <binBehavior>();
     myRend = gameObject.GetComponent <SpriteRenderer>();
     for (int i = 0; i < props.attrs.Length; i++)
     {
         if (props.attrs[i] == prop)
         {
             myRend.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
             break;
         }
         else
         {
             Debug.Log(prop);
             myRend.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
         }
     }
 }
 // Use this for initialization
 void Awake()
 {
     props = GetComponentInParent<binBehavior>();
     myRend = gameObject.GetComponent<SpriteRenderer>();
     for (int i = 0; i < props.attrs.Length; i++)
     {
         if (props.attrs[i] == prop)
         {
             myRend.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
             break;
         }
         else
         {
             Debug.Log(prop);
             myRend.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
         }
     }
 }