Пример #1
0
    /*
     * Called every frame
     */
    private void Update()
    {
        CheckValues();

        uint successes = 0;

        foreach (bool result in part_success.Values)
        {
            if (result)
            {
                successes++;
            }
        }

        if (successes == 3)
        {
            GenerateRobot();
            GetComponent <RobotGameManager>().ChangeScore(20);

            foreach (RobotPart part in FindObjectsOfType <RobotPart>())
            {
                if (part.transform.parent == null)
                {
                    RobotGoal goal = FindObjectOfType <RobotGoal>();

                    if (goal != null)
                    {
                        foreach (Transform child in goal.transform.GetComponentInChildren <Transform>())
                        {
                            if (part.transform.position == child.transform.position)
                            {
                                part.is_fading = true;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    /*
     * Loops through the robot parts to find a match
     */
    private void CheckValues()
    {
        foreach (RobotPart child in FindObjectsOfType <RobotPart>())
        {
            string test = "";
            //Finds parts that aren't children of the conveyor
            if (child.transform.parent == null)
            {
                RobotGoal goal = FindObjectOfType <RobotGoal>();
                //Check we're in the goal zone
                if (goal.in_bound)
                {
                    switch (child.part)
                    {
                    case RobotPartsEnum.PART_HEAD:
                    {
                        parts.TryGetValue("Head", out test);

                        ChangeValue("Head", test, child);

                        if (test == child.obj_name)
                        {
                            //Get "Head" child and set transform position to that
                            child.transform.position = goal.transform.GetChild(0).position;

                            if (!child.played_audio)
                            {
                                child.GetComponent <AudioSource>().Play();
                                child.played_audio = true;
                            }
                        }

                        break;
                    }

                    case RobotPartsEnum.PART_TORSO:
                    {
                        parts.TryGetValue("Torso", out test);

                        ChangeValue("Torso", test, child);

                        if (test == child.obj_name)
                        {
                            //Get "Torso" child and set transform position to that
                            child.transform.position = goal.transform.GetChild(1).position;
                            if (!child.played_audio)
                            {
                                child.GetComponent <AudioSource>().Play();
                                child.played_audio = true;
                            }
                        }

                        break;
                    }

                    case RobotPartsEnum.PART_LEGS:
                    {
                        parts.TryGetValue("Legs", out test);

                        ChangeValue("Legs", test, child);

                        if (test == child.obj_name)
                        {
                            //Get "Legs" child and set transform position to that
                            child.transform.position = goal.transform.GetChild(2).position;
                            if (!child.played_audio)
                            {
                                child.GetComponent <AudioSource>().Play();
                                child.played_audio = true;
                            }
                        }
                        break;
                    }
                    }
                    //Removes any excess speed to prevent 'flying'
                    child.GetComponent <Rigidbody>().velocity = Vector2.zero;
                }
            }
        }
    }