コード例 #1
0
ファイル: CharController.cs プロジェクト: t4lby/abfail
    public void PlatformHit(Collider2D platformCollider)
    {
        currentPlatformCollider = platformCollider;
        var speed = CharacterRbs.Select(rb => rb.velocity.magnitude).Sum() / CharacterRbs.Count();

        if (charStatus == Status.Falling)
        {
            health = speed / deathSpeed;
            SetHealth(health);
        }
        if (speed < deathSpeed &&
            charStatus == Status.Falling)
        {
            if (speed < deathSpeed / 2)
            {
                this.GetComponent <AudioSource>().clip =
                    GoodLandClips[Random.Range(0, GoodLandClips.Count - 1)];
                this.GetComponent <AudioSource>().Play();
            }
            else
            {
                this.GetComponent <AudioSource>().clip =
                    BadLandClips[Random.Range(0, BadLandClips.Count - 1)];
                this.GetComponent <AudioSource>().Play();
            }
            charStatus = Status.OnPlatform;
            platformTargetJoints.Add(this.gameObject.AddComponent <TargetJoint2D>());
            var feet = FindObjectsOfType <Transform>()
                       .Where(go => go.gameObject.CompareTag("foot"));
            foreach (var foot in feet)
            {
                platformTargetJoints.Add(foot.gameObject.AddComponent <TargetJoint2D>());
            }
            score         += 1;
            ScoreText.text = score.ToString();
            platformSpawner.SpawnNextPlatform(this);
            charAttemptedStop = false;
        }
        else if (charStatus == Status.Falling)
        {
            //kill
            this.GetComponent <AudioSource>().clip =
                DeathClips[Random.Range(0, DeathClips.Count - 1)];
            this.GetComponent <AudioSource>().Play();
            CharacterRbs
            .ForEach
            (
                SetRbDead
            );
            faceController.SetDead();
            cameraController.LookAhead = 0.1f;
            charStatus = Status.Dead;
            processUnlocks();
            if (PlayerPrefs.HasKey("BestScore"))
            {
                if (PlayerPrefs.GetInt("BestScore") < score)
                {
                    PlayerPrefs.SetInt("BestScore", score);
                }
            }
            else
            {
                PlayerPrefs.SetInt("BestScore", score);
            }
            finalScore.GetComponentInChildren <Text>().text = score.ToString();
            bestScore.GetComponentInChildren <Text>().text  = PlayerPrefs.GetInt("BestScore").ToString();
            StartCoroutine(WaitThenPostDeath(3.0f));
        }
    }