Пример #1
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (delayed)
        {
            return;
        }

        if (plyrs[i].myturn == false)   // if player finish the turn then we will let other player start.
        {
            if (i + 1 == plyrs.Length)
            {
                i = 0;                         // circle back to first player
            }
            else
            {
                i++;                // or go to next player
            }
            plyrs[i].myturn = true; // set next player turn to true

            // now set all toons can move and can attack bool to true so they can move again.
            GameObject[] toons = GameObject.FindGameObjectsWithTag("toons");
            foreach (GameObject toon in toons)
            {
                ProtoMove t = toon.GetComponent <ProtoMove>();
                if (t.owner == plyrs[i].pname)
                {
                    t.canattack = true; t.canmove = true;
                }
            }
        }
    }
Пример #2
0
 void CmdSpawn(string pname)
 {
     for (int i = 0; i < toons.Length; i++)
     {
         GameObject curtoon = (GameObject)Instantiate(toons[i], transform.position + transform.forward * 5 * (i + 1) + transform.up * 5, Quaternion.identity);
         NetworkServer.Spawn(curtoon);
         ProtoMove m = curtoon.GetComponent <ProtoMove>();
         m.owner = pname; m.pcolor = pcolor;
     }
 }
Пример #3
0
    public void CmdPlayerSpawn()
    {
        GameObject player = (GameObject)Instantiate(playerprefab[toontype - 1], toonpos.position, Quaternion.identity);
        ProtoMove  pm     = player.GetComponent <ProtoMove>();

        pm.owner  = toonowner;
        pm.type   = toontype;
        pm.pcolor = tooncolor;
        NetworkServer.Spawn(player);
    }
Пример #4
0
 void RpcPlayerSelected(GameObject go)
 {
     sltpm          = go.GetComponent <ProtoMove>();
     sltpm.selected = true;
 }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;                 // if i am not local player then get out of here.
        }
        // activating the "You Win/You Lose" screen at the end of the game
        if (gameover)
        {
            if (winning)
            {
                // GameObject.Find("WinGameOver").SetActive(true);
                canvas.SetActive(true);
                canvas.transform.GetChild(9).gameObject.SetActive(true); // WinGameOver

                // get player's score and show it along the game over screen
                canvas.transform.GetChild(11).gameObject.GetComponent <Text>().text = "FINAL SCORE : " + playerScore;
                canvas.transform.GetChild(11).gameObject.SetActive(true); // finalscore
                return;
            }
            else
            {
                // GameObject.Find("LoseGameOver").SetActive(true);
                canvas.SetActive(true);

                // get player's score and show it along the game over screen
                canvas.transform.GetChild(12).gameObject.GetComponent <Text>().text = "FINAL SCORE : " + playerScore;
                canvas.transform.GetChild(12).gameObject.SetActive(true); // finalscore
            }
        }

        if (Input.GetButton("up")) //if we click on ui button move (?)
        {
            transform.Translate(Vector3.forward * Time.deltaTime * 10);
        }
        else if (Input.GetButton("down")) // adding 1 more button (down = s) for camera to move backwards
        {
            transform.Translate(Vector3.back * Time.deltaTime * 10);
        }
        else if (Input.GetButton("left"))
        {
            //transform.rotation *= Quaternion.EulerRotation(0, -0.1f, 0);
            transform.rotation *= Quaternion.Euler(0, -5f, 0);
        }
        else if (Input.GetButton("right"))
        {
            //transform.rotation *= Quaternion.EulerRotation(0, 0.1f, 0);
            transform.rotation *= Quaternion.Euler(0, 5f, 0);
        }

        // if it's not my turn the dont show gui component.
        if (!myturn)
        {
            canvas.SetActive(false);
            setal = false;
            return;
        }
        else if (!setal)
        {
            canvas.SetActive(true);
            setal = true;
        }


        // if player press the endturn button then end player turn
        if (Input.GetButtonDown("endturn") || pbut.enddown)
        {
            CmdPlayerDeselected();
            CmdDestroyMat();
            CmdEndTurn();
            pbut.enddown = false; //unpress button
        }

        if (Input.GetButton("move") || pbut.movedown) //if we click on ui button move (?)
        {
            if (sltpm.canmove)
            {
                CmdSpawnMoveArea(); // spawn moveable area
                pbut.movedown = false;
            }
        }

        if (Input.GetButton("attack") || pbut.attackdown) //if we click on ui button attack (?)
        {
            if (sltpm.canattack)
            {
                CmdSpawnAttackArea(); //spawn attacking area (?)
                pbut.attackdown = false;
            }
        }


        // if player press fire1 / left mouse  then cast ray from screen
        if (Input.GetButton("Fire1"))
        {
            Debug.Log("Hello ");
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))             // if ray cast hit a collider then
            {
                if (hit.transform.name.StartsWith("toon")) // if i click on toons
                {
                    if (areaset)
                    {
                        CmdDestroyMat();          // destroy previous spawn move areas
                    }
                    if (sltpm)
                    {
                        CmdPlayerDeselected();                                      // deselect all toons
                    }
                    ProtoMove hitpm = hit.transform.GetComponent <ProtoMove>();     // get the new selected toon so i can compare

                    if (hitpm.owner == pname && (hitpm.canmove || hitpm.canattack)) // if it is a toon that i can control
                    {
                        CmdPlayerSelected(hit.transform.gameObject);                // then select that toon.
                    }
                    else if ((hitpm.owner != pname) && hitpm.canbeattack)
                    {
                        bool isBase = hit.transform.name.StartsWith("toonbase");

                        if (isBase)
                        {
                            if (playerScore >= 490)
                            {
                                winning = true;
                                CmdAttack(hitpm.moveto);
                            }
                            else
                            {
                                Debug.Log("You do not have enough power to destroy a base.");
                            }
                        }
                        else if (!isBase)
                        {
                            CmdAttack(hitpm.moveto);
                        }

                        // CmdDestroyGameObject(hitpm.gameObject);
                    }
                }
                else if (hit.transform.name.StartsWith("moveablearea") && sltpm.canmove) // if i am clicking on moveable area and my toon can move
                {
                    CmdMove(hit.point);                                                  // move the toon
                }
                CmdDestroyMat();                                                         // destroy areas.
            }
        }
    }
Пример #6
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (delayed)
        {
            return;
        }

        foreach (ProtoContrl player in plyrs)
        {
            if (player.winning)
            {
                GameOver();
                return;
            }
        }

        GameObject[] go = GameObject.FindGameObjectsWithTag("score");

        foreach (GameObject g in go)
        {
            if (g.name == "p1score")
            {
                g.GetComponent <Slider>().value = plyrs[0].playerScore;
                Debug.Log(g.name + ": " + plyrs[0].playerScore);

                /*
                 * GameObject textscore = GameObject.FindGameObjectWithTag("scorevalue");
                 * if (textscore.name == "p1scoreText")
                 * {
                 *  textscore.GetComponent<Text>().text = "" + plyrs[0].playerScore;
                 * }
                 */
            }
            else
            {
                g.GetComponent <Slider>().value = plyrs[1].playerScore;
                Debug.Log(g.name + ": " + plyrs[1].playerScore);
                //g.GetComponent<Text>().text = "" + plyrs[1].playerScore;
            }
        }



        if (plyrs[i].myturn == false)   // if player finish the turn then we will let other player start.
        {
            if (i + 1 == plyrs.Length)
            {
                i = 0;                         // circle back to first player
            }
            else
            {
                i++;                // or go to next player
            }
            plyrs[i].myturn = true; // set next player turn to true

            // now set all toons can move and can attack bool to true so they can move again.
            GameObject[] toons = GameObject.FindGameObjectsWithTag("toons");
            foreach (GameObject toon in toons)
            {
                ProtoMove t = toon.GetComponent <ProtoMove>();
                if (t.owner == plyrs[i].pname)
                {
                    t.canattack = true; t.canmove = true;
                }
            }
        }
    }
Пример #7
0
    // Update is called once per frame
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;                 // if i am not local player then get out of here.
        }
        // if it's not my turn the dont show gui component.
        if (!myturn)
        {
            canvas.SetActive(false); setal = false; return;
        }
        else if (!setal)
        {
            canvas.SetActive(true); setal = true;
        }


        // if player press the endturn button then end player turn
        if (CrossPlatformInputManager.GetButtonDown("endturn"))
        {
            CmdPlayerDeselected();
            CmdDestroyMat();
            CmdEndTurn();
        }

        if (CrossPlatformInputManager.GetButton("move")) //if we click on ui button move (?)
        {
            Debug.Log("Hello ");
            if (sltpm.canmove)
            {
                CmdSpawnMoveArea(); // spawn moveable area
            }
        }

        if (CrossPlatformInputManager.GetButton("attack")) //if we click on ui button attack (?)
        {
            if (sltpm.canattack)
            {
                CmdSpawnAttackArea(); //spawn attacking area (?)
            }
        }


        // if player press fire1 / left mouse  then cast ray from screen
        if (CrossPlatformInputManager.GetButton("Fire1"))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))             // if ray cast hit a collider then
            {
                if (hit.transform.name.StartsWith("toon")) // if i click on toons
                {
                    if (areaset)
                    {
                        CmdDestroyMat();          // destroy previous spawn move areas
                    }
                    if (sltpm)
                    {
                        CmdPlayerDeselected();                                      // deselect all toons
                    }
                    ProtoMove hitpm = hit.transform.GetComponent <ProtoMove>();     // get the new selected toon so i can compare

                    if (hitpm.owner == pname && (hitpm.canmove || hitpm.canattack)) // if it is a toon that i can control
                    {
                        CmdPlayerSelected(hit.transform.gameObject);                // then select that toon.
                    }
                    else if ((hitpm.owner != pname) && hitpm.canbeattack)
                    {
                        Vector3 temp = hitpm.moveto;

                        CmdAttack(temp);

                        CmdDestroyGameObject(hitpm.gameObject);
                    }
                }
                else if (hit.transform.name.StartsWith("moveablearea") && sltpm.canmove) // if i am clicking on moveable area and my toon can move
                {
                    CmdMove(hit.point);                                                  // move the toon
                }
                CmdDestroyMat();                                                         // destroy areas.
            }
        }
    }