Пример #1
0
        /// <summary>
        /// Levels up, resetting the targets and starting the next level
        /// </summary>
        void LevelUp()
        {
            // Increase the level
            currentLevel++;

            // Display the level text
            if (LevelText)
            {
                // Display the level text
                LevelText.text = LevelNamePrefix + " " + currentLevel.ToString();

                // Animate the level text
                if (LevelText.GetComponent <Animation>())
                {
                    LevelText.GetComponent <Animation>().Play();
                }
            }

            // Set the target count for the next level
            targetCount = targetsToWin;

            // Get a list of all targets
            //GameObject[] allTargets = GameObject.FindGameObjectsWithTag("Target");
            DWGTarget[] allTargets = DWGTarget.FindObjectsOfType <DWGTarget>();

            // Open all the targets so they can be hit again
            foreach (DWGTarget target in allTargets)
            {
                target.SendMessage("OpenTarget", transform);
            }

            // Increase the wheel speed
            wheelSpeed += wheelSpeedIncrease;

            // Switch the wheel direction
            wheelDirection *= -1;

            //switchChance += switchChanceIncrease;

            //If there is a source and a sound, play it from the source
            if (soundSourceTag != string.Empty && soundLevelUp)
            {
                GameObject.FindGameObjectWithTag(soundSourceTag).GetComponent <AudioSource>().PlayOneShot(soundLevelUp);
            }
        }
Пример #2
0
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        void Update()
        {
            // If the animation of the dart ended, then we can check if we hit anything.
            if (GetComponent <Animation>().isPlaying == false)
            {
                // Get a list of all targets
                //GameObject[] allTargets = GameObject.FindGameObjectsWithTag("Target");

                DWGTarget[] allTargets = DWGTarget.FindObjectsOfType <DWGTarget>();


                // Go through each target and check if we hit it
                foreach (DWGTarget target in allTargets)
                {
                    target.SendMessage("CheckHit", transform);
                }

                // If we didn't hit any targets, check if we hit the wheel behind them or the victim on the wheel
                if (hitTarget == false)
                {
                    // Check if we hit the victim
                    foreach (HitArea hitArea in victimObject.hitAreas)
                    {
                        if (hitArea.hitObject.OverlapPoint(transform.position))
                        {
                            // Drop the dart
                            DropDart();

                            // Run the hit function on the victim, making him get hurt
                            victimObject.SendMessage("HitVictim", transform);

                            // Switch to one of the hurt faces
                            if (victimObject.victimHead && hitArea.hurtFaces.Length > 0)
                            {
                                // Choose a random face
                                int randomFace = Mathf.FloorToInt(Random.Range(0, hitArea.hurtFaces.Length));

                                // Change the face of the victim
                                if (hitArea.hurtFaces[randomFace].faceSprite)
                                {
                                    victimObject.victimHead.GetComponent <SpriteRenderer>().sprite = hitArea.hurtFaces[randomFace].faceSprite;
                                }

                                //If there is a source and a sound, play it from the source
                                if (victimObject.soundSourceTag != string.Empty && hitArea.hurtFaces[randomFace].hurtSound)
                                {
                                    GameObject.FindGameObjectWithTag(victimObject.soundSourceTag).GetComponent <AudioSource>().PlayOneShot(hitArea.hurtFaces[randomFace].hurtSound);
                                }
                            }

                            // Reduce the number of lives the player has
                            GameObject.FindGameObjectWithTag("GameController").SendMessage("ChangeLives", -1);

                            // We hit the victim
                            hitVictim = true;

                            break;
                        }
                    }

                    if (hitVictim == false)                       // If we didn't hit the victim, it means we hit the wheel behind him, or missed the wheel entirely
                    {
                        // If we hit the wheel, stick the dart to it
                        if (wheelObject.GetComponent <Collider2D>().OverlapPoint(transform.position))
                        {
                            HitTarget(wheelObject.transform);
                        }
                        else                          // Otherwise, we missed the wheel entirely
                        {
                            MissTarget();

                            // Lose a life because we missed completely
                            GameObject.FindGameObjectWithTag("GameController").SendMessage("ChangeLives", -1);
                        }
                    }
                }

                // Remove the dart
                Destroy(gameObject);
            }
        }