Esempio n. 1
0
    public void DemoStage()
    {
        ResetPoint();
        player.ResetPlayer();
        player.DisableGravity();

        infoText.text    = INFO_TXT;
        infoText.enabled = true;
        retryBtn.enabled = false;

        animator.SetBool("isBirdBroken", false);

        ObsticleManager.DeleteAllObsticles();

        gameStage = GameStages.DEMO;
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        CharacterController controller = GetComponent <CharacterController>();
        Animator            anim       = GetComponent <Animator>();

        combatSc = GetComponent <Combat>();


        h = Input.GetAxis("Horizontal");
        v = Input.GetAxis("Vertical");
        // anim.SetBool("isGrounded", controller.isGrounded);

        if (controller.isGrounded && !isJumpingOverObsticle)
        {
            IsPlayerWalking();

            if (isWalking && Input.GetKey(KeyCode.LeftShift) && v > 0 && combatSc.isAiming == false)
            {
                speed       = sprintSpeed;
                isSprinting = true;
            }
            else
            {
                speed       = walkSpeed;
                isSprinting = false;
            }


            gravity = defaultGravity * 9;


            if (isSprinting)
            {
                h = 0;
            }

            moveDirection = new Vector3(h, 0, v);

            moveDirection  = transform.TransformDirection(moveDirection);
            moveDirection *= speed;
            AnimateMove(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), anim);



            if (Input.GetButton("Jump"))
            {
                RaycastHit hit;
                if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y - 0.5f, transform.position.z), transform.forward, out hit, 2.0f))
                {
                    ObsticleManager omSc = hit.collider.GetComponent <ObsticleManager>();
                    obsticalH = omSc.height;
                    obsticalL = omSc.length;
                    anim.SetBool("smallJover", true);
                    isJumpingOverObsticle = true;
                    endPos            = new Vector3(transform.position.x, transform.position.y + obsticalH + 0.7f, transform.position.z + hit.distance);
                    obsticleJumpSpeed = 0.12f;
                }
                else
                {
                    gravity         = defaultGravity;
                    moveDirection.y = jumpspeed;
                }
            }

            moveDirection.y -= gravity * Time.deltaTime;
            controller.Move(moveDirection * Time.deltaTime);
        }
        else if (isJumpingOverObsticle)
        {
            gravity            = 0.0f;
            transform.position = Vector3.Lerp(transform.position, endPos, obsticleJumpSpeed);

            if (Vector3.Distance(transform.position, endPos) < 0.5f && curJumpstate == 0)
            {
                endPos            = new Vector3(transform.position.x, transform.position.y, transform.position.z + obsticalL + 1f);
                curJumpstate     += 1;
                obsticleJumpSpeed = 0.04f;
            }
            else if (Vector3.Distance(transform.position, endPos) < 1f && curJumpstate == 1)
            {
                endPos            = new Vector3(transform.position.x, transform.position.y - obsticalH - 0.5f, transform.position.z + 0.5f);
                curJumpstate     += 1;
                obsticleJumpSpeed = 0.15f;
                anim.SetBool("smallJover", false);
            }
            else if (Vector3.Distance(transform.position, endPos) < 0.15f && curJumpstate == 2)
            {
                curJumpstate          = 0;
                isJumpingOverObsticle = false;
            }
        }
        else
        {
            isWalking        = false;
            gravity          = defaultGravity;
            moveDirection.y -= gravity * Time.deltaTime;
            controller.Move(moveDirection * Time.deltaTime);
        }
    }
Esempio n. 3
0
    // ---------------------------------------------------------------------------------------------------------------------------------------------
    // OTHER FUNCTIONS
    // ---------------------------------------------------------------------------------------------------------------------------------------------

    // Return an index for a random object to spawn from a list of prefabs.
    // This will return and index depending on the prefabs rarity weight.
    // Keep rarity between 0.001 - 100 on prefab stats.
    public int ChooseRandomSpawn(List <GameObject> list)
    {
        float x           = 0; // counter
        float totalRarity = 0; // tht total rarity weight of all in the list
        int   index       = 0; // return this index

        if (list.Count >= 0)
        {
            // get total rarity
            for (int i = 0; i < list.Count; i++)
            {
                // check if target or obsticle
                if (list[i].GetComponentsInChildren <TargetManager>().Length != 0)
                {
                    TargetManager tmScript = list[i].GetComponentInChildren <TargetManager>();
                    totalRarity += tmScript.rarity;
                }
                else
                {
                    ObsticleManager tmScript = list[i].GetComponentInChildren <ObsticleManager>();
                    totalRarity += tmScript.rarity;
                }
            }

            // get random number from the total rarity weight
            x = Random.Range(0, totalRarity);

            // Step through the list and check if x is less than the rarity.
            // If x is less than the rarity then break out of the loop and
            // return the index;
            for (int i = 0; i < list.Count; i++)
            {
                index = i;

                //TargetManager tmScript = list[i].GetComponentInChildren<TargetManager>();
                //float rarity = tmScript.rarity;
                float rarity = 0;

                // check if target or obsticle
                if (list[i].GetComponentsInChildren <TargetManager>().Length != 0)
                {
                    TargetManager tmScript = list[i].GetComponentInChildren <TargetManager>();
                    rarity = tmScript.rarity;
                }
                else
                {
                    ObsticleManager tmScript = list[i].GetComponentInChildren <ObsticleManager>();
                    rarity = tmScript.rarity;
                }


                if (x <= rarity)
                {
                    break;
                }

                x -= rarity;
            }
        }
        return(index);
    }
Esempio n. 4
0
 private void Start()
 {
     GetPlatformsAndSetLastX();
     obsticleManager = FindObjectOfType <ObsticleManager>();
 }