示例#1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (dead)
        {
            return;
        }

        string val = collision.tag;

        if (val == "Pair")
        {
            //if complete live
            //else take damage and maybe die
            TrackPair pair = collision.GetComponent <TrackPair>();
            if (pair.Damaged)
            {
                Rb.velocity = Tools.RandomDirection(Rb.velocity, 10.0f, 100.0f);
                //float angle = Mathf.Deg2Rad * (Random.Range(10.0f, 100.0f) * (Random.Range(0, 2) == 0 ? 1 : -1));
                //Rb.velocity = new Vector2(Mathf.Cos(angle) * Rb.velocity.x - Mathf.Sin(angle) * Rb.velocity.y,
                //Mathf.Sin(angle) * Rb.velocity.x + Mathf.Cos(angle) * Rb.velocity.y);
                Rb.velocity *= 0.75f;
                pair.Repair(false);
                Source.PlayOneShot(SkipSounds[Random.Range(0, SkipSounds.Length)]);
                Player.LoseTrain();
                Die();
            }
            else
            {
                if (pair.Fixed)
                {
                    Player.AddToScore(TravelledPairValue);
                }
            }
        }
        else if (val == "Link")
        {
            //Get new destinaiton
            collision.GetComponent <TrainLink>().SetNextDirection(this);
        }
    }