Пример #1
0
    public void ChangeDice(string diceType)
    {
        DiceType myDiceType = DiceManager.SearchDiceType(diceType);

        if (myDiceType != null)
        {
            this.gameObject.SetActive(true);
            this.GetComponent <Animator>().runtimeAnimatorController = myDiceType.GetAnimationController();
            m_OnDiceStopped  = myDiceType.GetOnStoppedEvent();
            m_OnAttack       = myDiceType.GetOnAttackEvent();
            m_OnStatusEffect = myDiceType.GetOnStatusEvent();
        }
        else
        {
            this.gameObject.SetActive(false);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (_startAttack)
        {
            List <Character> targets = DiceManager.GetCurrTargets();
            float            step    = speed * Time.deltaTime; // calculate distance to move

            if (!_hasMovedToAttackPos)
            {
                Vector3 targetPos = GameObject.Find("AttackTarget").transform.position;
                targetPos.y = DiceManager.GetCurrCharacter().gameObject.transform.position.y;
                targetPos.z = DiceManager.GetCurrCharacter().gameObject.transform.position.z;

                if (Vector3.Distance(DiceManager.GetCurrCharacter().gameObject.transform.position, targetPos) > 0.1f)
                {
                    DiceManager.GetCurrCharacter().gameObject.transform.position = Vector3.MoveTowards(DiceManager.GetCurrCharacter().gameObject.transform.position, targetPos, step);
                }
                else
                {
                    foreach (Character c in targets)
                    {
                        //Manage damage animations
                        if (c.tag.Contains("Player"))
                        {
                            GameObject.Find("Ayanda").GetComponent <Animator>().SetBool("takingDamage", true);
                        }
                        else
                        {
                            if (!TutorialManager.IsTutorial())
                            {
                                GameObject.Find("AyandaMonster").GetComponent <Animator>().SetBool("takingDamage", true);
                            }
                        }

                        //Manage particle effects
                        AudioManager.PlaySound(Resources.Load("Explosions") as AudioClip);

                        for (int i = 0; i < _attacks.Count; i++)
                        {
                            GameObject particles   = Resources.Load(_attacks[i].GetMyType()) as GameObject;
                            Vector3    particlePos = c.transform.position;
                            particlePos.z -= 3;

                            Instantiate(particles, particlePos, Quaternion.identity);
                        }
                    }
                    _hasMovedToAttackPos = true;
                }
            }
            else if (!_hasPlayedAttackAnim)
            {
                _animationTimer += Time.deltaTime;

                if (_animationTimer >= animationWaitTime)
                {
                    _animationTimer = 0.0f;


                    Character currChar = DiceManager.GetCurrCharacter();

                    for (int i = 0; i < _attacks.Count; i++)
                    {
                        DiceManager.ExecuteAttack(_attacks[i].GetMyAP());
                        DiceType myDiceType = DiceManager.SearchDiceType(_attacks[i].GetMyType());
                        m_OnCurrAttack = myDiceType.GetOnAttackEvent();
                        m_OnCurrAttack.Invoke();
                    }

                    _hasPlayedAttackAnim = true;
                }
            }
            else
            {
                DiceManager.GetCurrCharacter().gameObject.transform.position = Vector3.MoveTowards(DiceManager.GetCurrCharacter().gameObject.transform.position, _originalPos, step);

                if (Vector3.Distance(DiceManager.GetCurrCharacter().gameObject.transform.position, _originalPos) > 0.1f)
                {
                    DiceManager.GetCurrCharacter().gameObject.transform.position = Vector3.MoveTowards(DiceManager.GetCurrCharacter().gameObject.transform.position, _originalPos, step);
                }
                else
                {
                    _startAttack         = false;
                    _hasMovedToAttackPos = false;
                    _hasPlayedAttackAnim = false;

                    //VERY IMPORTANT MAKE SURE THIS LINE IS IN EVERY ABILITY!!!
                    GameObject.Find("AttackHolder").GetComponent <AttackHolder>().ClearAttacks();
                    TurnManager.FinishAttack();
                }
            }
        }
    }