void Start()
    {
        hpImage   = GameObject.Find("currentHP").GetComponent <Image>();
        manaImage = GameObject.Find("currentMana").GetComponent <Image>();

        experienceBar  = GameObject.Find("currentXp").GetComponent <Image>();
        playerLevelTxt = GameObject.Find("playerLevelTxt").GetComponent <Text>();

        charactermotor   = gameObject.GetComponent <CharacterMotor>();
        playerAnimations = gameObject.GetComponent <Animation>();

        damageScreenRepeatTime = damageScreenTime;
        playerSkill            = gameObject.GetComponent <playerSkills>();
        playerMagics           = gameObject.GetComponent <playerMagic>();

        if (inputManagerDatabase == null)
        {
            inputManagerDatabase = (InputManager)Resources.Load("InputManager");
        }

        if (craftSystem != null)
        {
            cS = craftSystem.GetComponent <CraftSystem>();
        }

        if (GameObject.FindGameObjectWithTag("Tooltip") != null)
        {
            toolTip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent <Tooltip>();
        }
        if (inventory != null)
        {
            mainInventory = inventory.GetComponent <Inventory>();
        }
        if (characterSystem != null)
        {
            characterSystemInventory = characterSystem.GetComponent <Inventory>();
        }
        if (craftSystem != null)
        {
            craftSystemInventory = craftSystem.GetComponent <Inventory>();
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!animator.GetBool("Death"))
        {
            //keyNumber.text = collectedKey.ToString() + "/" + keyOnMap.ToString();
            //Test health
            if (Input.GetKeyDown(KeyCode.O))
            {
                health.CurrentValue -= 20;
            }
            if (Input.GetKeyDown(KeyCode.P))
            {
                health.CurrentValue += 20;
            }

            // set element into storedMagic, depends on OntriggerEnter2D and Exit
            if (Input.GetButtonDown("PickUpMagic"))
            {
                if (storedMagicFlag == "Fire")
                {
                    StartCoroutine(DisablePowerUp(powerUp));
                    storedMagic = playerMagic.FIRE;
                }
                else if (storedMagicFlag == "Ice")
                {
                    StartCoroutine(DisablePowerUp(powerUp));
                    storedMagic = playerMagic.ICE;
                }
            }

            if (isAttacking)
            {
                if (comboCD > 0)
                {
                    comboCD -= Time.deltaTime;
                }
                else //finished
                {
                    if (animator.GetBool("AttackCombo"))
                    {
                        comboCD = comboCDStart;
                        animator.SetBool("AttackCombo", false);
                    }
                    else
                    {
                        animator.SetBool("Attacking", false);
                        isAttacking = false;
                    }
                }
            }
            else //isAttacking = false
            {
                horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; //outside the if !cover to avoid keep moving when run and cover bug
            }
            animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
            animator.SetFloat("VelocityY", Rb.velocity.y); //detects the Y speed for jump animation
            bool jumpButton = Input.GetButtonDown("Jump");


            bool useMagicButton = Input.GetButtonDown("UseMagic"); //e

            /*
             * When activate magic, check storadMagic and use that magic, if same element is in use set refreshMagic as true (important for
             * ElementIconEffect). After activating set storadmagig to Neutral
             */
            if (useMagicButton)
            {
                if (storedMagic.ToString() == "FIRE")
                {
                    if (activeMagic.ToString() == "FIRE")
                    {
                        refreshMagic = true;
                    }
                    else
                    {
                        activeMagic = playerMagic.FIRE;
                    }
                }
                else if (storedMagic.ToString() == "ICE")
                {
                    if (activeMagic.ToString() == "ICE")
                    {
                        refreshMagic = true;
                    }
                    else
                    {
                        activeMagic = playerMagic.ICE;
                    }
                }
                storedMagic = playerMagic.NEUTRAL;
            }

            /*use magic
             *  if (useMagicButton && activeMagic.ToString() == "NEUTRAL" && storedMagic.ToString() != "NEUTRAL")
             *  {
             *          //StartCoroutine("UseMagic");
             *  }*/

            if (!playerIsCovering)
            {
                bool attackButton = Input.GetButtonDown("Attack");
                if (attackButton && horizontalMove == 0 && Rb.velocity.y == 0) //if press attack
                {
                    AttackCalc.CalculateImpact();                              //raycast and hit handler
                    if (!isAttacking)                                          //and we were on idle
                    {
                        isAttacking = true;
                        animator.SetBool("Attacking", true);
                        comboCD = comboCDStart;
                    }
                    else //if we press in the middle of an attack
                    {
                        animator.SetBool("AttackCombo", true);
                    }
                }

                if (jumpButton)
                {
                    jump = true;
                }

                if (Input.GetButtonDown("Cover") && horizontalMove == 0 && Rb.velocity.y == 0) //if we press cover and we are not moving
                {
                    playerIsCovering = true;
                    animator.SetBool("IsCovering", true);
                }
            }

            if (Input.GetButtonUp("Cover") && playerIsCovering) //stop covering
            {
                playerIsCovering = false;
                animator.SetBool("IsCovering", false);
            }
        }
        else
        {
            StartCoroutine(Respawn());
            horizontalMove = 0;
            animator.SetFloat("VelocityY", 0);             //cutre
        }
    }
예제 #3
0
 //actually this is a setter (is in use in ElementIconEffect)
 public void beNeutral()
 {
     activeMagic = playerMagic.NEUTRAL;
 }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        if (previousVelocity != 0 && Rb.velocity.y == 0)
        {
            FindObjectOfType <AudioManager>().Play("floorImpact");
        }
        if (!animator.GetBool("Death"))
        {
            keyNumber.text = collectedKey.ToString() + "/" + keyOnMap.ToString();

            // set element into storedMagic, depends on OntriggerEnter2D and Exit
            if (Input.GetButtonDown("PickUpMagic")) //PICKUPMAGIC
            {
                if (storedMagicFlag == "Fire")
                {
                    FindObjectOfType <AudioManager>().Play("fireElementPickUp");
                    StartCoroutine(DisablePowerUp(powerUp));
                    storedMagic = playerMagic.FIRE;
                }
                else if (storedMagicFlag == "Ice")
                {
                    FindObjectOfType <AudioManager>().Play("iceElementPickUp");
                    StartCoroutine(DisablePowerUp(powerUp));
                    storedMagic = playerMagic.ICE;
                }
            }

            //if !isAttacking to avoid moving while attacking
            if (controller.finished == true)
            {
                horizontalMove = 0;
            }
            else
            {
                horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed; //outside the if !cover to avoid keep moving when run and cover bug
            }
            animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
            animator.SetFloat("VelocityY", Rb.velocity.y); //detects the Y speed for jump animation
            bool jumpButton = Input.GetButtonDown("Jump");

            bool useMagicButton = Input.GetButtonDown("UseMagic"); //e

            //When activate magic, check storadMagic and use that magic, if same element is in use set refreshMagic as true (important for ElementIconEffect). After activating set storadmagig to Neutral
            if (useMagicButton)
            {
                if (storedMagic.ToString() == "FIRE")                //MAGIC USE
                {
                    FindObjectOfType <AudioManager>().Play("fireUse");
                    FindObjectOfType <AudioManager>().Play("usingMagic");
                    StartCoroutine(ShortAnimationPlay("UseMagic"));
                    ppEffects.activateChromaticAberration();                     //postProcessing effect

                    if (activeMagic.ToString() == "FIRE")
                    {
                        refreshMagic = true;
                    }
                    else
                    {
                        activeMagic = playerMagic.FIRE;
                    }
                }
                else if (storedMagic.ToString() == "ICE")                //MAGIC USE
                {
                    FindObjectOfType <AudioManager>().Play("iceUse");
                    FindObjectOfType <AudioManager>().Play("usingMagic");
                    StartCoroutine(ShortAnimationPlay("UseMagic"));
                    ppEffects.activateChromaticAberration();                     //postProcessing effect

                    if (activeMagic.ToString() == "ICE")
                    {
                        refreshMagic = true;
                    }
                    else
                    {
                        activeMagic = playerMagic.ICE;
                    }
                }
                storedMagic = playerMagic.NEUTRAL;
            }

            if (!playerIsCovering)
            {
                if (jumpButton)
                {
                    jump = true;
                }
            }


            if (Input.GetButtonDown("Cover") && horizontalMove == 0 && Rb.velocity.y == 0)     //if we press cover and we are not moving
            {
                playerIsCovering = true;
                animator.SetBool("IsCovering", true);
            }

            if (Input.GetButtonUp("Cover") && playerIsCovering) //stop covering
            {
                playerIsCovering = false;
                animator.SetBool("IsCovering", false);
            }
        }        //if (!animator.GetBool("Death"))
        else
        {
            StartCoroutine("Respawn");
            horizontalMove = 0;
            animator.SetFloat("VelocityY", 0);             //cutre
        }
        previousVelocity = Rb.velocity.y;
    }