示例#1
0
    public override void Tick()
    {
        base.Tick();

        movementDirection = Vector3.zero;
        isSprinting       = false;
        isWalking         = false;

        if (UIMaster.GetState() == UIState.FOCUSED)
        {
            return;                                         //  Don't allow interaction while the UI is focused
        }
        if (GameMaster.GetState() != GameState.PLAYING)
        {
            return;                                             //  Don't allow interaction while the gamestate isn't in play mode
        }
        if (Input.GetButton("Forward"))
        {
            movementDirection += Vector3.forward;
        }
        if (Input.GetButton("Backward"))
        {
            movementDirection += Vector3.back;
        }
        if (Input.GetButton("Left"))
        {
            movementDirection += Vector3.left;
        }
        if (Input.GetButton("Right"))
        {
            movementDirection += Vector3.right;
        }

        if (movementDirection != Vector3.zero && Input.GetButton("Sprint") && HasEndurance(Constants.END_COST_SPRINT))
        {
            isSprinting = true;
        }

        if (movementDirection != Vector3.zero && Input.GetButton("Walk"))
        {
            isWalking = true;
        }

        if (isGrounded == true)
        {
            if (Input.GetButton("Jump") && CostModifyEndurance(Constants.END_COST_JUMP))
            {
                velocity.y = jumpStrength;

                isJumping = true;
            }
        }

        if (Input.GetButton("Attack"))
        {
            Attack();
        }

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // Offset interact range based on camera distance. Offset is relative to character facing, so invert it
        float range = interactRange;

        if (cameraMotor.view == CameraMotor.CameraView.THIRD_PERSON)
        {
            range += -cameraMotor.thirdPersonOffset.z;
        }
        else if (cameraMotor.view == CameraMotor.CameraView.FIRST_PERSON)
        {
            range += -cameraMotor.fpOffset.z;
        }

        if (Physics.Raycast(ray, out hit, range, interactableMask) == true)
        {
            Interactable component = hit.collider.gameObject.GetComponent <Interactable>();

            if (component != null)
            {
                UIMaster.GetHook("look_display").Enable();
                UIMaster.SendText(UITextType.SUBTEXT, component.GetDisplayText());

                if (Input.GetButton("Interact"))
                {
                    component.Interact(this);
                }
            }
            else
            {
                UIMaster.GetHook("look_display").Disable();
            }
        }

        if (Input.GetKeyDown(KeyCode.T))
        {
            Swordfish.Terrain terrain = GameObject.Find("Terrain").GetComponent <Swordfish.Terrain>();

            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z, 1);
            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z + 1, 1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z + 1, 1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z, 1);
            terrain.ModifyTerrain((int)transform.position.x - 1, (int)transform.position.z + 1, 1);
            terrain.ModifyTerrain((int)transform.position.x - 1, (int)transform.position.z, 1);
            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z - 1, 1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z - 1, 1);

            transform.position += new Vector3(0, 2, 0);
        }
        else if (Input.GetKeyDown(KeyCode.Y))
        {
            Swordfish.Terrain terrain = GameObject.Find("Terrain").GetComponent <Swordfish.Terrain>();

            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z, -1);
            terrain.ModifyTerrain((int)transform.position.x, (int)transform.position.z + 1, -1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z + 1, -1);
            terrain.ModifyTerrain((int)transform.position.x + 1, (int)transform.position.z, -1);
        }
    }