示例#1
0
    // Update is called once per frame
    void Update()
    {
        //check if the unit is selected
        if (_casterMoveInput.isSelected)
        {
            //enable or disable spellcast on keypress
            if (Input.GetKeyUp(spellHotkey1))
            {
                buttonPressed = 1;
                Button1Animation.GetComponentInParent <Button>().onClick.Invoke();
            }
            else if (Input.GetKeyUp(spellHotkey2))
            {
                Button2Animation.GetComponentInParent <Button>().onClick.Invoke();
                buttonPressed = 2;
            }
            else if (Input.GetKeyUp(spellHotkey3))
            {
                Button3Animation.GetComponentInParent <Button>().onClick.Invoke();
                buttonPressed = 3;
            }
            else if (Input.GetKeyUp(spellHotkey4))
            {
                Button4Animation.GetComponentInParent <Button>().onClick.Invoke();
                buttonPressed = 4;
            }
            else if (Input.GetKeyUp(spellHotkey5))
            {
                Button5Animation.GetComponentInParent <Button>().onClick.Invoke();
                buttonPressed = 5;
            }
            else if (Input.GetKeyUp(spellHotkey6))
            {
                toggleMovement();
            }
        }

        //if the caster has an ability selected
        if (usingAbility == true)
        {
            //if the left mouse button is pressed
            if (Input.GetButtonUp("Fire1"))
            {
                //cast a ray from the main camera to the mouse
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100))
                {
                    //if the ray hits an object with the Unit tag
                    if (hit.collider.tag == "UI")
                    {
                        hit = new RaycastHit();
                    }
                    else if (hit.collider.tag == "Unit")
                    {
                        if (canCast(hit.collider.gameObject.GetComponent <CharacterStatus>(), abilityUsed) != -1)
                        {
                            //cast an ability
                            if (buttonPressed == 1)
                            {
                                copyInfo(Button1Animation);
                                gameObject.GetComponentInParent <CastSpell>().callCast(hit.collider.gameObject.GetComponent <CharacterStatus>(),
                                                                                       abilityUsed, 1);
                            }
                            if (buttonPressed == 2)
                            {
                                copyInfo(Button2Animation);
                                gameObject.GetComponentInParent <CastSpell>().callCast(hit.collider.gameObject.GetComponent <CharacterStatus>(),
                                                                                       abilityUsed, 2);
                            }
                            if (buttonPressed == 3)
                            {
                                copyInfo(Button3Animation);
                                gameObject.GetComponentInParent <CastSpell>().callCast(hit.collider.gameObject.GetComponent <CharacterStatus>(),
                                                                                       abilityUsed, 3);
                            }
                            if (buttonPressed == 4)
                            {
                                copyInfo(Button4Animation);
                                gameObject.GetComponentInParent <CastSpell>().callCast(hit.collider.gameObject.GetComponent <CharacterStatus>(),
                                                                                       abilityUsed, 4);
                            }
                            if (buttonPressed == 5)
                            {
                                copyInfo(Button5Animation);
                                gameObject.GetComponentInParent <CastSpell>().callCast(hit.collider.gameObject.GetComponent <CharacterStatus>(),
                                                                                       abilityUsed, 5);
                            }
                        }
                        //ability has been cast so de-select it
                        usingAbility = false;
                        abilityUsed  = 0;
                    }
                }
            }
        }
    }