예제 #1
0
    /*
     * Makes a connection between two stars
     * Returns the new selected star
     * */
    public StarData ConnectStars(StarData selectedStar, StarData clickedStar)
    {
        if (!clickedStar.GetConnectedFrom())
        {
            selectedStar.SetConnectsTo(clickedStar.star);
            clickedStar.SetConnectedFrom(selectedStar.star);

            Debug.Log("Connecting stars...");
            // Visual cues
            // Shine star
            selectedStar.star.transform.Find("Star_Bloom").gameObject.GetComponent <SpriteRenderer>().color = new Color(255, 255, 255, 255);
            // Draw connection
            LineDrawingManager.instance.DrawLine(selectedStar, clickedStar);
            // Create particles over connected star
            ParticleManager.instance.CreateStarConnectedParticle(selectedStar.star.transform.position);

            if (CountConnections() == starData.Count)
            {
                LineDrawingManager.instance.SetLoop(true);
            }
            // Checks if, with this connection, all connections were made
            if (AllStarsConnected())
            {
                Debug.Log("Level Ended! All stars connected");
                LevelManager.instance.EndLevel();
            }

            return(clickedStar);
        }
        return(selectedStar);
    }
예제 #2
0
    // LateUpdate is called after Update
    void LateUpdate()
    {
        // Mouse left click
        if (Input.GetMouseButtonDown(0))
        {
            // Does not allow star selection if all stars are connected
            if (StarManager.instance.AllStarsConnected())
            {
                // Allow only clicking in UI elements, such as NEXT LEVEL
            }
            else
            {
                Debug.Log("Selected star: " + selectedStar.star.name);

                // Collision detection to check if a GameObject was clicked
                Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Collider2D[] col      = Physics2D.OverlapCircleAll(mousePos, 0.02f);

                if (col.Length > 0)
                {
                    Collider2D collider = (Collider2D)col.GetValue(0); // Collider of the GameObject clicked
                    GameObject parent   = collider.gameObject;         // GameObject clicked
                    clickedStar = StarManager.instance.GetStarFromGameObject(parent);

                    // Star cannot be itself
                    if (clickedStar != selectedStar)
                    {
                        // Check if the clickedStar does not have a connection
                        if (!clickedStar.GetConnectedFrom())
                        {
                            selectedStar = StarManager.instance.ConnectStars(selectedStar, clickedStar);
                        }
                    }
                }
            }
        }
    }