Exemple #1
0
    private void OnMouseUp()
    {
        if (gearSelected)
        {
            gear.GetComponent <SpriteRenderer>().sprite = null;
            AudioManager.Instance.PlaySound("set");
            gearSelected = false;

            float tempD = Mathf.Infinity;
            float curD;

            GearPos closestPos = myPos;

            foreach (var item in gearsPos)
            {
                curD = Vector3.Distance(transform.position, item.transform.position);
                if (tempD > curD && item.myGear.canBeSwappd)
                {
                    tempD      = curD;
                    closestPos = item;
                }
            }
            if (closestPos != myPos && canBeSwappd && closestPos.myGear.canBeSwappd)
            {
                AudioManager.Instance.PlaySound("swap");

                MiniGame.Instance.SwapGears(this, closestPos.myGear);
            }

            else
            {
                transform.position = myPos.transform.position;
            }
        }
    }
Exemple #2
0
    public void SwapGears(Gear gear1, Gear gear2)
    {
        GearPos temp = gear1.myPos;

        gear1.myPos        = gear2.myPos;
        gear2.myPos        = temp;
        gear1.myPos.myGear = gear1;
        gear2.myPos.myGear = gear2;


        StartCoroutine(fadeOut(gear1.GetComponentInParent <SpriteRenderer>(), gear2.GetComponentInParent <SpriteRenderer>()));
        fading = true;
    }
Exemple #3
0
    void Update()
    {
        float   tempD          = Mathf.Infinity;
        Vector2 screenPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

        foreach (var item in gearsPos)
        {
            curD = Vector3.Distance(new Vector3(MiniGame.Instance.cam.ScreenToWorldPoint(screenPosition).x, MiniGame.Instance.cam.ScreenToWorldPoint(screenPosition).y, transform.position.z), item.transform.position);
            if (tempD > curD && item.myGear.canBeSwappd)
            {
                tempD      = curD;
                closestPos = item;
            }
        }
        transform.position = closestPos.transform.position;
    }