Exemplo n.º 1
0
    void Awake()
    {
        myButton = GetComponent <Button>(); // <-- you get access to the button component here

        player       = GameObject.FindGameObjectWithTag("Player");
        PlayerScript = player.GetComponent <ThirdPersonUserControl>();
        GameObject enemy = GameObject.FindGameObjectWithTag("Enemy");

        EnemyScript = enemy.GetComponent <SkeletonBehavior>();
        Animator animator = enemy.GetComponent <Animator>();

        asi = animator.GetCurrentAnimatorStateInfo(0);


        myButton.onClick.AddListener(() => { myFunctionForOnClickEvent(); });  // <-- you assign a method to the button OnClick event here
    }
Exemplo n.º 2
0
        private void Update()
        {
            if (!m_Jump)
            {
                m_Jump = Input.GetButtonDown("Jump");
            }
            if (battle)
            {
                setLimits();
                mainInventory.closeInventory();
                characterSystemInventory.closeInventory();
                float hp   = currentHealth;
                float mana = currentMana;
                if (healthBar == null || ManaBar == null)
                {
                    healthBar = (Camera.main.transform.FindChild("Canvas").FindChild("PlayerHealth").FindChild("PlayerLife")).gameObject;
                    ManaBar   = (Camera.main.transform.FindChild("Canvas").FindChild("PlayerMana").FindChild("PlayerMana")).gameObject;
                }

                if (healthBar.transform.localScale.x * 100 != hp)
                {
                    print("entrei no id da vida");
                    Vector3 temp = healthBar.transform.localScale;
                    temp.x = hp / 100f;
                    if (hp / 100 < 0)
                    {
                        temp.x = 0;
                    }
                    healthBar.transform.localScale = temp;
                }
                if (ManaBar.transform.localScale.x * 50 != mana)
                {
                    Vector3 temp = ManaBar.transform.localScale;
                    temp.x = mana / 100f;
                    if (mana / 100 < 0)
                    {
                        temp.x = 0;
                    }
                    ManaBar.transform.localScale = temp;
                }

                GameObject enemy = GameObject.FindGameObjectWithTag("Enemy");
                EnemyScript = enemy.GetComponent <SkeletonBehavior>();

                if (hp <= 0)
                {
                    defeat.SetActive(true);
                    buttonContinue.SetActive(true);
                    battle             = false;
                    EnemyScript.battle = false;
                }
            }
            else
            {
                if (Input.GetKeyDown(inputManagerDatabase.CharacterSystemKeyCode))
                {
                    if (!characterSystem.activeSelf)
                    {
                        characterSystemInventory.openInventory();
                    }
                    else
                    {
                        characterSystemInventory.closeInventory();
                    }
                }

                if (Input.GetKeyDown(inputManagerDatabase.InventoryKeyCode))
                {
                    if (!inventory.activeSelf)
                    {
                        mainInventory.openInventory();
                    }
                    else
                    {
                        mainInventory.closeInventory();
                    }
                }
            }
        }