示例#1
0
    public void OnDeath(GameObject other)
    {
        FindObjectOfType <Splat>().DoSplat(transform.position, 0, (int)color);

        /*
         * //splat
         * GameObject splatObject = new GameObject("splatInstance");
         * splatObject.transform.position = this.gameObject.transform.position;
         * SpriteRenderer SR = splatObject.AddComponent<SpriteRenderer>();
         * SR.flipX = UnityEngine.Random.Range(0, 2) == 0? false : true;
         * SR.flipY = UnityEngine.Random.Range(0, 2) == 0 ? false : true;
         *
         * SR.sortingOrder = -14;  //before background but behind the rest
         * SheetAnimation ani = splatObject.AddComponent<SheetAnimation>();
         * LevelBounds.instance.RegisterObject(splatObject, true);
         * ani.PlayAnimation("Splat", color, false, 1);
         */
        /*
         * //shield powerup / spawn immunity
         * if(Immunity)
         * {
         *  if (!StayImmune) Immunity = false;
         *  IC();
         *  return;
         * }*/
        //score
        //Debug.Log(other.name + gameObject.name);
        int playerID     = other.name.Contains("1") ? 0 : (other.name.Contains("2") ? 1 : (other.name.Contains("3") ? 2 : 3));
        int thisplayerID = gameObject.name.Contains("1") ? 0 : (gameObject.name.Contains("2") ? 1 : (gameObject.name.Contains("3") ? 2 : 3));

        if (playerID == thisplayerID)
        {
            return;
        }
        //if (playerID > ScoreManager.instance.score.Length) playerID = 1;
        int useingID = ScoreManager.instance.scoreMode == ScoreManager.ScoreMode.Health ? thisplayerID : playerID;

        ScoreManager.instance.ChangeScore(useingID, ScorePerKill);
        if (ScoreManager.instance.scoreMode == ScoreManager.ScoreMode.Health && ScoreManager.instance.score[useingID] <= 0)
        {
            Respawn = false;
        }



        //Tag mode
        if (ScoreManager.instance.gameMode is TagMode)
        {
            TagMode Tagmode = (TagMode)ScoreManager.instance.gameMode;
            if (Tagmode.currentTag == other)
            {
                Tagmode.RemoveTag(other);
                //if (other.GetComponentInChildren<PlayerHit>())
                Tagmode.SetTag(gameObject);
            }

            /*
             * else if (Tagmode.currentTag == other)
             * {
             *  ScoreManager.instance.ChangeScore(playerID, 5);//bonus points if you are the Tag
             * }*/
        }
        else

        if (ScoreManager.instance.gameMode is OwnedMode)
        {
            OwnedMode ownedMode = (OwnedMode)ScoreManager.instance.gameMode;
            ownedMode.SetOwned(gameObject, other);
        }
        else

        //chicken mode
        if (ScoreManager.instance.gameMode is ChickenMode)
        {
            ChickenMode chickenmode = (ChickenMode)ScoreManager.instance.gameMode;
            if (chickenmode.currentChicken == gameObject || chickenmode.currentChicken == null)
            {
                chickenmode.RemoveChicken(gameObject);
                if (other.GetComponentInChildren <PlayerHit>())
                {
                    chickenmode.SetChicken(other);
                }
            }
            else if (chickenmode.currentChicken == other)
            {
                ScoreManager.instance.ChangeScore(playerID, 5);//bonus points if you are the chicken
            }
        }


        float          deathTime = 0.5f;
        PlayerMovement pm        = isClone ? gameObject.transform.parent.gameObject.GetComponent <PlayerMovement>() : GetComponent <PlayerMovement>();

        pm.StunnedTimer = deathTime;
        Rigidbody2D rig = isClone ? gameObject.transform.parent.gameObject.GetComponent <Rigidbody2D>() : GetComponent <Rigidbody2D>();

        rig.gravityScale = 0;
        rig.velocity     = Vector2.zero;
        rig.isKinematic  = true;
        PowerupUser pu = isClone? gameObject.transform.parent.gameObject.GetComponent <PowerupUser>() : GetComponent <PowerupUser>();

        pu.EndAllPowerups();
        Array.ForEach(GetComponentsInChildren <Collider2D>(), x => x.isTrigger = true);
        SheetAnimation sa = isClone ? gameObject.transform.parent.gameObject.GetComponent <SheetAnimation>() : GetComponent <SheetAnimation>();

        sa.PlayAnimation("Death", color, false, 5.0f / deathTime);
        StartCoroutine(DelayedRespawn(deathTime));

        /*
         * if (Respawn)
         * {
         *  PlayerMovement pm = gameObject.GetComponent<PlayerMovement>();
         *  if (pm == null) pm = gameObject.transform.parent.GetComponent<PlayerMovement>();
         *  PlayerMovement.Controls controls = pm.controls;
         *  pm.gameObject.transform.position = SpawnManager.instance.GetRandomSpawnPoint();
         * }
         * else
         * {
         *  GameObject.Destroy(this.gameObject);
         * }*/
    }