Пример #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "HostHealth")
        {
            if (!isOffline & isServer)
            {
                Player player = col.gameObject.GetComponent <Player>();
                if (CanDoubleDamage)
                {
                    Debug.Log(col.gameObject);
                    NetPlayer.CmdDecideDoubleDamage(col.gameObject.GetComponent <NetworkIdentity>().netId);
                }
                else
                {
                    player.GetDamage();
                }
                NetworkServer.Destroy(gameObject);
            }
            if (isOffline)
            {
                PlayerOff player = col.gameObject.GetComponent <PlayerOff>();
                player.GetDamage();
                Destroy(gameObject);
            }
        }
        if (col.gameObject.tag == "ClientHealth")
        {
            if (!isOffline & !isServer)
            {
                Player player = col.gameObject.GetComponent <Player>();
                if (CanDoubleDamage)
                {
                    NetPlayer.CmdDecideDoubleDamage(col.gameObject.GetComponent <NetworkIdentity>().netId);
                }
                else
                {
                    player.GetDamage();
                }
                Debug.Log("DEstroy" + gameObject);
                NetPlayer.CmdDestroy(gameObject.GetComponent <NetworkIdentity>().netId);
            }
            if (isOffline)
            {
                if (CanDoubleDamage)
                {
                    float         Rate         = Random.Range(0f, 100f);
                    PlayerOff     player       = col.gameObject.GetComponent <PlayerOff>();
                    EnemySpawnOff SpawnManager = FindObjectsOfType <EnemySpawnOff>()[0].GetComponent <EnemySpawnOff>();
                    Debug.Log(Rate);
                    Debug.Log(SpawnManager.DoubleDamageRate);
                    if (Rate <= SpawnManager.DoubleDamageRate)
                    {
                        Debug.Log("Double");
                        player.Lives -= 2;
                        player.UpdateLive();
//						player.gameObject.GetComponent<AudioSource>().Play();
                        if (player.Lives <= 0)
                        {
                            FindObjectsOfType <GameManageNewOff>()[0].GetComponent <GameManageNewOff>().DefineWinLose(player);
                        }
                        Destroy(gameObject);
                    }
                    else
                    {
                        player = col.gameObject.GetComponent <PlayerOff>();
                        player.GetDamage();
                        Destroy(gameObject);
                    }
                }
                else
                {
                    PlayerOff player2 = col.gameObject.GetComponent <PlayerOff>();
                    player2.GetDamage();
                    Destroy(gameObject);
                }
            }
        }
    }