Example #1
0
    //void OnTriggerExit (Collider other) {}

    protected void Swap(SwappableStar other, bool swapBack)
    {
        // Disable halo
        if (halo != null)
        {
            halo.SetON(false);
        }

        // Change paint balls
        if (!swapBack)
        {
            int tmp = other.GetPositionID();
            other.SetPositionID(positionID);
            positionID = tmp;
            // Swap colors
            cloud.SwapColors(other.cloud);
            // Swap objects
            GameObject otherCloudObj = other.cloudObj;
            other.SetCloud(this.cloudObj);
            SetCloud(otherCloudObj);
        }

        // Initialize animation
        srcPos       = transform.position;
        dstPos       = other.transform.position;
        swapping     = true;
        swapProgress = 0;

        // Trigger swapping on the other star
        if (swapBack)
        {
            other.Swap(this, false);
        }

        // Detach the star during the animation
        Level.Get.Detach(gameObject);

        // Check if the new position is good
    }
Example #2
0
    void OnTriggerEnter(Collider other)
    {
        if (!swapping)
        {
            DrakeScale drakeScale = other.GetComponent <DrakeScale>();
            if (drakeScale != null && drakeScale.HasMoonPaint)
            {
                Drake drake = drakeScale.drakeRef;

                if (drake.LastTouchedStar == null)
                {
                    // First star selected !
                    if (halo != null)
                    {
                        halo.SetON(true);
                    }
                    drake.LastTouchedStar = gameObject;
                }
                else
                {
                    SwappableStar otherStar =
                        drake.LastTouchedStar.GetComponent <SwappableStar>();

                    // If the star exist and is different
                    if (otherStar != null && otherStar != this)
                    {
                        drake.LastTouchedStar = null;

                        // Second star selected, swapping !
                        Swap(otherStar, true);
                        SoundLevel2.Instance.SwapStar();
                    }
                }
            }
        }
    }