Esempio n. 1
0
    void OnGUI()
    {
        //display messages
        if (Time.time < textDisplayTime)
        {
            for (int i = 0; i < 8; i++)
            {
                if (i < messages.Count)
                {
                    Color guiColA = GUI.color;

                    //highlight
                    GUI.color = new Color(1, 1, 1, 0.5f);
                    GUI.Label(new Rect(10, Screen.height - 55 - (i * 15) - 1, 500, 20), messages[messages.Count - i - 1].sender + " " + messages[messages.Count - i - 1].message);

                    //drop shadow
                    GUI.color = new Color(0, 0, 0, 0.5f);
                    //GUI.color = new Color((messages[messages.Count-i-1].senderColor.r * -1) + 0.5f, (messages[messages.Count-i-1].senderColor.g * -1) + 0.5f, (messages[messages.Count-i-1].senderColor.b * -1) + 0.5f, 1);
                    GUI.Label(new Rect(11, Screen.height - 55 - (i * 15) + 1, 500, 20), messages[messages.Count - i - 1].sender + " " + messages[messages.Count - i - 1].message);
                    //GUI.Label(new Rect(9,Screen.height - 55 - (i*15) -1, 500, 20), messages[messages.Count-i-1].sender + " " + messages[messages.Count-i-1].message);

                    //normal
                    GUI.color = messages[messages.Count - i - 1].senderColor;
                    //GUI.color = new Color(messages[messages.Count-i-1].senderColor.r + 0.25f, messages[messages.Count-i-1].senderColor.g + 0.25f, messages[messages.Count-i-1].senderColor.b + 0.25f, 1);
                    GUI.Label(new Rect(10, Screen.height - 55 - (i * 15), 500, 20), messages[messages.Count - i - 1].sender + " " + messages[messages.Count - i - 1].message);

                    GUI.color = guiColA;
                }
            }
        }
        if (chatTextEntry)
        {
            textDisplayTime = Time.time + textFadeTime;

            Event e = Event.current;
            if (e.keyCode == KeyCode.Escape)
            {
                chatTextEntry   = false;
                chatTextMessage = "";
            }
            else if (e.keyCode == KeyCode.Return)
            {
                chatTextEntry = false;

                if (chatTextMessage != "")
                {
                    if (theNetwork.connected)
                    {
                        networkView.RPC("SendChatMessage", RPCMode.All, theNetwork.localPlayer.name + ":", chatTextMessage, theNetwork.ColToVec(theNetwork.localPlayer.colA));
                    }
                    else
                    {
                        SendChatMessage(theNetwork.localPlayer.name + ":", chatTextMessage, theNetwork.ColToVec(theNetwork.localPlayer.colA));
                    }
                }


                chatTextMessage = "";
            }
            else
            {
                GUI.SetNextControlName("TextField");
                chatTextMessage = GUI.TextField(new Rect(10, Screen.height - 35, 500, 20), chatTextMessage);
                GUI.FocusControl("TextField");
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (held)
        {
            gameObject.layer = 13;              //no hit
            watchdog         = 0f;
            watchdogOn       = true;
        }
        else
        {
            gameObject.layer = 13;              //ball
            if (watchdogOn)
            {
                watchdog += Time.deltaTime;

                if (watchdog > 15f)
                {
                    watchdog = 0f;
                    ResetBall();
                    if (theNetwork.isServer)
                    {
                        theNetwork.networkView.RPC("SendChatMessage", RPCMode.All, "> ", "Ball reset.", theNetwork.ColToVec(new Color(1f, 0.5f, 0f, 1f)));
                    }
                }
            }

            transform.position += moveVector * Time.deltaTime;

            moveVector.y -= Time.deltaTime * 18f;

            RaycastHit hitInfo      = new RaycastHit();
            int        layerMask    = (1 << 0) | (1 << 10) | (1 << 11) | (1 << 12);
            Vector3    rayDirection = (transform.position - lastPos).normalized;
            if (Physics.SphereCast(lastPos, 0.5f, rayDirection, out hitInfo, Vector3.Distance(transform.position, lastPos), layerMask))
            {
                if (hitInfo.collider.gameObject.layer == 11)
                {
                    //blue scores
                    ResetBall();

                    if (!SophieNetworkScript.gameOver)
                    {
                        for (int i = 0; i < theNetwork.players.Count; i++)
                        {
                            theNetwork.players[i].fpsEntity.Announce("scoreblue");
                        }

                        if (theNetwork.isServer)
                        {
                            theNetwork.team2Score++;
                            theNetwork.networkView.RPC("AnnounceTeamScores", RPCMode.Others, theNetwork.team1Score, theNetwork.team2Score);
                            theNetwork.networkView.RPC("SendChatMessage", RPCMode.All, "> ", "Blue scores.", theNetwork.ColToVec(new Color(1f, 0.5f, 0f, 1f)));
                        }
                    }
                }
                else if (hitInfo.collider.gameObject.layer == 12)
                {
                    //red scores
                    ResetBall();

                    if (!SophieNetworkScript.gameOver)
                    {
                        for (int i = 0; i < theNetwork.players.Count; i++)
                        {
                            theNetwork.players[i].fpsEntity.Announce("scorered");
                        }

                        if (theNetwork.isServer)
                        {
                            theNetwork.team1Score++;
                            theNetwork.networkView.RPC("AnnounceTeamScores", RPCMode.Others, theNetwork.team1Score, theNetwork.team2Score);
                            theNetwork.networkView.RPC("SendChatMessage", RPCMode.All, "> ", "Red scores.", theNetwork.ColToVec(new Color(1f, 0.5f, 0f, 1f)));
                        }
                    }
                }
                else if (hitInfo.collider.gameObject.layer == 10)
                {
                    //LAVA! :D
                    ResetBall();

                    for (int i = 0; i < theNetwork.players.Count; i++)
                    {
                        theNetwork.players[i].fpsEntity.Announce("balllost");
                    }

                    if (theNetwork.isServer)
                    {
                        theNetwork.networkView.RPC("SendChatMessage", RPCMode.All, "> ", "Ball lost.", theNetwork.ColToVec(new Color(1f, 0.5f, 0f, 1f)));
                    }
                }
                else
                {
                    transform.position = hitInfo.point + (hitInfo.normal * 0.5f);
                    moveVector         = Vector3.Reflect(moveVector, hitInfo.normal);
                    moveVector        *= 0.7f;

                    //Debug.Log(moveVector.magnitude);
                    if (moveVector.magnitude > 2f)
                    {
                        audio.clip  = sfx_bounce;
                        audio.pitch = Random.Range(0.9f, 1.1f);
                        audio.Play();
                    }
                }
            }
            lastPos = transform.position;

            if (theNetwork.isServer)
            {
                //let's check to see if any of the players can pick up the ball
                bool captured = false;
                for (int i = 0; i < theNetwork.players.Count; i++)
                {
                    if (!captured && theNetwork.players[i].health > 0f && Vector3.Distance(transform.position, theNetwork.players[i].fpsEntity.transform.position) < 1.5f)
                    {
                        if (throwerID == null || theNetwork.players[i].viewID != throwerID || Time.time > throwTime + 0.5f)
                        {
                            theNetwork.AnnounceBallCapture(theNetwork.players[i].viewID);
                            captured = true;
                        }
                    }
                }

                //Sync:

                lastSync -= Time.deltaTime;
                if (lastSync < 0)
                {
                    lastSync = 5f;
                    theNetwork.SyncBall(transform.position, moveVector);
                }
            }
        }
    }