示例#1
0
    void IEntity.EUpdate(float delta)
    {
        if (Spatial == null)
        {
            Spatial = FindObjectOfType <SpatialIndex>();
        }

        mIsGrounded = Physics.CheckSphere(GroundCheck.position, GroundDistance, GroundMask);

        if (mIsGrounded && mVelocity.y < 0)
        {
            mVelocity.y = -2f;

            Spatial.GetFloorState(transform.position.x, transform.position.z, gameObject);
        }

        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move = transform.right * x + transform.forward * z;

        Controller.Move(move * Speed * Time.deltaTime);

        if (Input.GetButtonDown("Jump") && mIsGrounded)
        {
            mVelocity.y = Mathf.Sqrt(JumpHeight * -2f * Physics.gravity.y);
        }

        if (!FlyMode)
        {
            mVelocity += Physics.gravity * Time.deltaTime;
            Controller.Move(mVelocity * Time.deltaTime);
        }
    }