示例#1
0
        public void SitClick(string param2)
        {
            //WorldConnection2.DoSit();
            //Stand.SetActive(true);
            //Sit.SetActive(false);

            WorldConnection2.DoClientUpdate();
        }
        //Every Frame
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.F10))
            {
                Screen.fullScreen = !Screen.fullScreen;
            }

            if (Input.GetKeyDown("return"))
            {
                if (chatting == true)
                {
                    ToggleChatOff();
                }
                else
                {
                    ToggleChatOn();
                }
            }

            if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("CastHeal"))
            {
                Casting              = true;
                moveStatus           = "CastHeal";
                UIScripts.CastButton = false;
            }
            else
            {
                Casting = false;
            }
            //Set idel animation
            isWalking = true;

            // Hold "Run" to run
            if (Input.GetAxis("Run") != 0)
            {
                isWalking = false;
            }

            // Only allow movement and jumps while grounded
            if (grounded)
            {
                //movedirection
                if (WorldConnection.isTyping == false)
                {
                    moveDirection = new Vector3((Input.GetMouseButton(1) ? Input.GetAxis("Horizontal") : 0), 0, Input.GetAxis("Vertical"));
                }
                //pushbuffer to avoid on/off flipping
                if (pbuffer > 0)
                {
                    pbuffer -= Time.deltaTime;
                }
                if (pbuffer < 0)
                {
                    pbuffer = 0;
                }

                //Automove Sidebuttonmovement
                if ((Input.GetAxis("Toggle Move") != 0) && pbuffer == 0)
                {
                    pbuffer         = coolDown;
                    mouseSideButton = !mouseSideButton;
                }

                //L+R MouseButton Movement
//				if (Input.GetMouseButton(0) && Input.GetMouseButton(1) || mouseSideButton)
//					moveDirection.z += 1;
//				if (moveDirection.z > 1)
//					moveDirection.z = 1;

                //Strafing move (like Q/E movement
                moveDirection.x -= Input.GetAxis("Strafing");

                // if moving forward and to the side at the same time, compensate for distance
                if (Input.GetMouseButton(1) && (Input.GetAxis("Horizontal") != 0) && (Input.GetAxis("Vertical") != 0))
                {
                    moveDirection *= 0.7f;
                }

                //Speedmodification / is moving forward or side/backward
                speedMod = ((Input.GetAxis("Vertical") < 0) || (Input.GetMouseButton(1) && (Input.GetAxis("Horizontal")) != 0) || Input.GetAxis("Strafing") != 0) ? walkBackMod : 1.0f;

                //Use run or walkspeed
                moveDirection *= isWalking ? walkSpeed * speedMod : runSpeed * speedMod;

                //reduce movement by 70% when swimming is toggled
                moveDirection *= swimming ? 0.7f : 1;

                // Jump!
                if (Input.GetButton("Jump") && (Casting == false) && (WorldConnection.isTyping == false))
                {
                    jumping         = true;
                    moveDirection.y = jumpSpeed;
                    GetComponent <Animator>().Play("Jump");
                }


                var turningright = (Input.GetAxis("Horizontal") > 0);
                var turningleft  = (Input.GetAxis("Horizontal") < 0);

                if ((turningright == true) && (moveDirection.z == 0) && (Casting == false) && (moveDirection.x == 0) && (moveDirection.y == 0) && (WorldConnection.isTyping == false))
                {
                    moveStatus = "Turn";
                    GetComponent <Animator>().Play("Turn");
                }
                if ((turningleft == true) && (moveDirection.z == 0) && (Casting == false) && (moveDirection.x == 0) && (moveDirection.y == 0) && (WorldConnection.isTyping == false))
                {
                    moveStatus = "Turn";
                    GetComponent <Animator>().Play("Turn");
                }
                //movestatus normal movement (for animations)
                if ((moveDirection.x == 0) && (moveDirection.z == 0) && (turningright == false) && (turningleft == false))
                {
                    if ((UIScripts.CastButton == true) && (moveStatus == "idle"))
                    {
                        GetComponent <Animator>().Play("CastHeal");
                        UIScripts.CastButton = false;
                    }

                    if (Casting == false && UIScripts.CastButton == false)
                    {
                        moveStatus = "idle";
                        GetComponent <Animator>().Play("Idle");
                    }
                }
                if ((Casting == false) && (WorldConnection.isTyping == false))
                {
                    if (moveDirection.z > 0)
                    {
                        UIScripts.CastButton = false;
                        moveStatus           = isWalking ? "walking" : "running";
                        GetComponent <Animator>().Play("Walk");
                    }
                    if (moveDirection.z < 0)
                    {
                        UIScripts.CastButton = false;
                        moveStatus           = isWalking ? "backwalking" : "backrunning";
                        GetComponent <Animator>().Play("Walk");
                    }
                    if (moveDirection.x > 0)
                    {
                        UIScripts.CastButton = false;
                        moveStatus           = isWalking ? "sidewalking_r" : "siderunning_r";
                        GetComponent <Animator>().Play("Walk");
                    }
                    if (moveDirection.x < 0)
                    {
                        UIScripts.CastButton = false;
                        moveStatus           = isWalking ? "sidewalking_l" : "siderunning_l";
                        GetComponent <Animator>().Play("Walk");
                    }
                }
                //movestatus swim movement (for animations)
                if (swimming)
                {
                    if ((moveDirection.x == 0) && (moveDirection.z == 0))
                    {
                        moveStatus = "swimidle";
                    }
                    if (moveDirection.z > 0)
                    {
                        moveStatus = isWalking ? "swim" : "swimfast";
                    }
                    if (moveDirection.z < 0)
                    {
                        moveStatus = isWalking ? "backswim" : "backswimfast";
                    }
                    if (moveDirection.x > 0)
                    {
                        moveStatus = isWalking ? "sideswim_r" : "sideswimfast_r";
                    }
                    if (moveDirection.x < 0)
                    {
                        moveStatus = isWalking ? "sidewswim_l" : "sideswimfast_l";
                    }
                    if (jumping)
                    {
                        moveStatus = "swimup";
                    }
                }

                //transform direction
                moveDirection = transform.TransformDirection(moveDirection);

                //clientupdate

                distanceTravelled += Vector3.Distance(transform.position, lastPosition);
                lastPosition       = transform.position;

                rotationTravelled += Vector3.Distance(transform.eulerAngles, lastRotation);
                lastRotation       = transform.eulerAngles;

                if (distanceTravelled > 3)
                {
                    distanceTravelled = 0;
                    WorldConnection.DoClientUpdate();
                }

                if (rotationTravelled > 3)
                {
                    rotationTravelled = 0;
                    WorldConnection.DoClientUpdate();
                }
            }
            // Allow turning at anytime. Keep the character facing in the same direction as the Camera if the right mouse button is down.
            if (Input.GetMouseButton(1))
            {
//				transform.rotation = Quaternion.Euler(0,Camera.main.transform.eulerAngles.y,0);
            }
            else
            {
                if (WorldConnection.isTyping == false)
                {
                    transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime, 0);
                }
            }

            //Apply gravity
            moveDirection.y -= gravity * Time.deltaTime;

            //Get CharacterController
            controller = GetComponent <CharacterController>();

            //Move Charactercontroller and check if grounded
            if (WorldConnection.isTyping == false)
            {
                grounded = ((controller.Move(moveDirection * Time.deltaTime)) & CollisionFlags.Below) != 0;
            }

            //Reset jumping after landing
            jumping = grounded ? false : jumping;

            //movestatus jump/swimup (for animations)
            if (jumping)
            {
                moveStatus = "jump";
            }
            if (jumping && swimming)
            {
                moveStatus = "swimup";
            }
        }