Example #1
0
 private void Start()
 {
     anim   = GetComponent <NetworkAnimator>();
     health = GetComponent <PlayerHealth>();
     //transform.position = new Vector3(-80, 0.3f, 409);
     sync = this.GetComponent <Player_Sync>();
 }
Example #2
0
    /************************************************************************************/
    public void Respawn()
    {
        var conn          = GetComponent <NetworkIdentity>().connectionToClient;
        var playerToSpawn = Instantiate <GameObject>(Player0, Vector3.zero, transform.rotation);

        if (playerPrefab == 0)
        {
            Destroy(playerToSpawn);
            playerToSpawn = Instantiate <GameObject>(Player1, Vector3.zero, transform.rotation);
        }


        Player_Sync sync_team = playerToSpawn.GetComponent <Player_Sync>();

        if (playerPrefab == 0)
        {
            sync_team.playerPrefab = 1;
        }
        else if (playerPrefab == 1)
        {
            sync_team.playerPrefab = 0;
        }
        sync_team.team    = team;
        sync_team.changed = true;
        // RpcSpawn(playerToSpawn,sync_team);
        Destroy(GetComponent <NetworkIdentity>().gameObject);
        NetworkServer.ReplacePlayerForConnection(conn, playerToSpawn, 0);
    }
        public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
        {
            GameObject player = null;

            if (conn.connectionId % 2 == 0)
            {
                player = (GameObject)Instantiate(gamePlayerPrefab, Vector3.zero, Quaternion.identity);
                Player_Sync sync_team = player.GetComponent <Player_Sync>();
                sync_team.team         = team;
                sync_team.playerPrefab = 1;
                //Debug.Log("charachter1: "+sync_team.team);
            }
            else
            {
                player = (GameObject)Instantiate(Player2, Vector3.zero, Quaternion.identity);
                Player_Sync sync_team = player.GetComponent <Player_Sync>();
                sync_team.team         = team;
                sync_team.playerPrefab = 2;
                //  Debug.Log("charachter2: " + sync_team.team);
                team++;
            }


            id++;
            return(player);
        }
    [Command] public void CmdISelected(int index)
    {
        GameObject[] players1 = GameObject.FindGameObjectsWithTag("Player");
        Player_Sync  thisPS   = GetComponent <Player_Sync>();

        if (!thisPS)
        {
            return;
        }
        foreach (GameObject p in players1)
        {
            Player_Sync otherPS = p.GetComponent <Player_Sync>();
            if (!otherPS)
            {
                continue;
            }
            if (thisPS.team == otherPS.team)
            {
                PlayerAttacks otherPA = p.GetComponent <PlayerAttacks>();
                if (!otherPA)
                {
                    return;
                }
                otherPA.otherPlayerSelected = index;
                Debug.Log("server updated selected weapon on teamamte");

                return;//finished everyting so we can stop and return
            }
        }
    }
Example #5
0
    //all the players send the team number to rest of the players
    private void Update()
    {
        //Sync the team and the player prefab to all of the clients
        Cmdteam();
        CmdPrefab();
        if (isServer)
        {
            Rpcteam(team);
            RpcPrefab(playerPrefab);
        }


        if (playerPrefab == 1)
        {
            //search for the player with the same team
            find();
        }
        else if (playerPrefab == 0)
        {
            if (!myTeamMate)
            {
                players2 = GameObject.FindGameObjectsWithTag("Player2");
                Player_Sync[] s1 = new Player_Sync[players2.Length];
                for (int i = 0; i < players2.Length; i++)
                {
                    s1[i] = players2[i].GetComponent <Player_Sync>();
                }

                for (int i = 0; i < s1.Length; i++)
                {
                    if (s1[i].team == this.team && s1[i].team != 100)
                    {
                        myTeamMate = players2[i];
                    }
                }
            }
            if (!defined)
            {
                health = GetComponent <PlayerHealth>();
            }
            if (health != null && health.death)
            {
                //if the player dies respawn him to the second prefab
                StartCoroutine(gg());
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     if (!isLocalPlayer)
     {
         return;
     }
     for (int i = 0; i < gunsImages.Length; i++)
     {
         if (gunsImages[i] != null)
         {
             gunsImages[i].enabled = false;
         }
     }
     sync  = this.GetComponent <Player_Sync>();
     guns  = new int[4];
     taked = new int[4];
     //treasure_key.enabled = false;
     doors_key.enabled = false;
 }
Example #7
0
    /**************************************************************************************/

    private void find()
    {
        if (!findTeamMate)
        {
            //get all the players in the game that thier tags is "Player"
            players1 = GameObject.FindGameObjectsWithTag("Player");
            Player_Sync[] s = new Player_Sync[players1.Length];
            for (int i = 0; i < players1.Length; i++)
            {
                s[i] = players1[i].GetComponent <Player_Sync>();
            }

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i].team == this.team && this.team != 100)
                {
                    // Debug.Log(s[i].team + " myteam : " +this.team);
                    myTeamMate = players1[i];
                    Vector3 temp = players1[i].transform.position;
                    temp.y = temp.y + 5f;
                    temp.x = temp.x - 1f;
                    Player2Camera player2Cam = GetComponentInChildren <Player2Camera>();
                    if (player2Cam != null)
                    {
                        player2Cam.setplayer(players1[i].transform);
                        findTeamMate = true;
                        health       = players1[i].GetComponent <PlayerHealth>();
                    }
                }
            }
        }
        else if (myTeamMate == null || myTeamMate.GetComponent <PlayerHealth>().death)
        {
            StartCoroutine(gg());
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            StartCoroutine(gg());
        }
    }
Example #8
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }
        /*************************************************************/

        if (Input.GetKeyDown(KeyCode.P))
        {
            selfControl = !selfControl;
        }
        if (myTeamMate != null && takeGuns != null)
        {
            if (Input.GetKeyDown(KeyCode.Mouse0) && HasFirePower && GetComponent <AimBehaviourBasic>().Aiming() && !GetComponent <PlayerHealth>().death)
            {
                //ShootingPoint.transform.position = cam.transform.position;
                ShootingPoint.transform.rotation = cam.transform.rotation;
                FireAttack(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                //anim.SetTrigger("Attacking");
                CmdDoFire(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                if (isServer)
                {
                    RpcDoFire(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                }
            }
            /*************************************************************/
            if (Input.GetKeyDown(KeyCode.Mouse0) && HasElectricPower && GetComponent <AimBehaviourBasic>().Aiming() && !GetComponent <PlayerHealth>().death)
            {
                ShootingPoint.transform.rotation = cam.transform.rotation;
                ElectrecAttack(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                CmdDoElictric(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                if (isServer)
                {
                    RpcDoElictric(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                }
            }
            /*************************************************************/
            if (Input.GetKeyDown(KeyCode.Mouse0) && HasWaterPower && GetComponent <AimBehaviourBasic>().Aiming() && !GetComponent <PlayerHealth>().death)
            {
                ShootingPoint.transform.rotation = cam.transform.rotation;
                WaterAttack(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                CmdDoWater(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                if (isServer)
                {
                    RpcDoWater(this.ShootingPoint.transform.position, this.ShootingPoint.transform.rotation);
                }
            }

            if (Input.GetKeyDown(KeyCode.Mouse0) && HasHealthPower && !GetComponent <PlayerHealth>().death)
            {
                PlayerHealth health = this.GetComponent <PlayerHealth>();
                if (health.health < 100)
                {
                    if (health.health > 90)
                    {
                        health.health = 100;
                    }
                    else
                    {
                        this.GetComponent <PlayerHealth>().health += 10;
                    }
                }
            }
            PlayerAttackType();
        }
        else
        {
            sync       = this.GetComponent <Player_Sync>();
            myTeamMate = sync.getTeamMate();
            if (myTeamMate != null)
            {
                takeGuns = myTeamMate.GetComponent <takeGuns>();
            }
            else
            {
                print("teammate is null");
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        CmdSelect(selected);
        /*get the team mate*/
        if (myTeamMate == null || TeamMateCollect == null)
        {
            sync       = this.GetComponent <Player_Sync>();
            myTeamMate = sync.getTeamMate();
            if (myTeamMate != null)
            {
                TeamMateCollect = myTeamMate.GetComponent <Collect_PowerUp>();
            }
        }

        if (myTeamMate != null)//treasure key
        {
            try
            {
                if (myTeamMate.GetComponent <status>().hasKey)
                {
                    treasure_key.enabled = true;
                }

                if (myTeamMate.GetComponent <PlayerHealth>().hasDoorKey)
                {
                    doors_key.enabled = true;
                }
            }
            catch (System.Exception e)
            {
                print(e);
            }
        }


        if (TeamMateCollect != null)  //when the teammate take somthing this player and set the correct image

        {
            if (TeamMateCollect.Elictricity != guns[EIndex])
            {
                guns[EIndex] = TeamMateCollect.Elictricity;
                setPic(EIndex);
            }
            if (TeamMateCollect.Fire != guns[FIndex])
            {
                guns[FIndex] = TeamMateCollect.Fire;
                setPic(FIndex);
            }
            if (TeamMateCollect.Water != guns[WIndex])
            {
                guns[WIndex] = TeamMateCollect.Water;
                setPic(WIndex);
            }
            if (TeamMateCollect.Health != guns[HIndex])
            {
                guns[HIndex] = TeamMateCollect.Health;
                setPic(HIndex);
            }
            if (TeamMateCollect.WaterD != WaterD)
            {
                WaterD = TeamMateCollect.WaterD;
                setPic(WdIndex);
            }
            if (TeamMateCollect.ElictricityD != ElictricityD)
            {
                ElictricityD = TeamMateCollect.ElictricityD;
                setPic(EdIndex);
            }
            if (TeamMateCollect.FireD != FireD)
            {
                FireD = TeamMateCollect.FireD;
                setPic(FdIndex);
            }
        }


        //selecting the gun
        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            selectgun(0);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            selectgun(1);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            selectgun(2);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            selectgun(3);
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            isDefend = !isDefend;
            if (wallToSpawn != null)
            {
                Destroy(wallToSpawn);
            }
        }

        if (isDefend)//creating walls to defend
        {
            if (Cam != null)
            {
                myRay = Cam.ScreenPointToRay(Input.mousePosition);
            }
            else
            {
                print("cam is null");
            }
            if (Physics.Raycast(myRay, out hit, 4000))
            {
                if (wallToSpawn == null)
                {
                    wallToSpawn = Instantiate(Wall1, hit.point, Quaternion.Euler(90, 180, 0));
                    wallToSpawn.transform.position += up;
                }
                else
                {
                    if (hit.collider.tag == "ground")
                    {
                        wallToSpawn.transform.position  = hit.point;
                        wallToSpawn.transform.position += up;
                    }

                    if (Input.GetKeyDown(KeyCode.Space))
                    {
                        wallToSpawn.transform.Rotate(0, 0, 45);
                    }
                }
            }
            if (Input.GetMouseButtonDown(0))
            {
                if (wallToSpawn != null)
                {
                    if (isServer)
                    {
                        Defend(wallToSpawn.transform.position, wallToSpawn.transform.rotation);
                    }
                    else
                    {
                        CmdDefend(wallToSpawn.transform.position, wallToSpawn.transform.rotation);
                    }
                    Destroy(wallToSpawn);
                    isDefend = !isDefend;
                }
            }
        }
    }