コード例 #1
0
    private void Awake()
    {
        p_Velocity     = Vector2.zero;
        cc_Rb          = GetComponent <Rigidbody>();
        cr_Anim        = GetComponent <Animator>();
        cr_Renderer    = GetComponentInChildren <Renderer>();
        p_DefaultColor = cr_Renderer.material.color;

        p_FrozenTimer   = 0;
        p_CurrentHealth = m_MaxHealth;
        for (int i = 0; i < m_Attacks.Length; i++)
        {
            PlayAttackInfo attack = m_Attacks[i];
            attack.Cooldown = 0;

            if (attack.WindUpTime > attack.FrozenTime)
            {
                Debug.LogError(attack.AttackName + " has a wind up time that is larger than the amount of time that the player is frozen for");
            }
        }
    }
コード例 #2
0
    private IEnumerator UseAttack(PlayAttackInfo attack)
    {
        cc_Rb.rotation = Quaternion.Euler(0, m_CameraTransform.eulerAngles.y, 0);
        cr_Anim.SetTrigger(attack.TriggerName);

        IEnumerator toColor = ChangeColor(attack.AbilityColor, 10);

        StartCoroutine(toColor);
        yield return(new WaitForSeconds(attack.WindUpTime));

        Vector3    offset = transform.forward * attack.Offset.z + transform.right * attack.Offset.x + transform.up * attack.Offset.y;
        GameObject go     = Instantiate(attack.AbilityGO, transform.position + offset, cc_Rb.rotation);

        go.GetComponent <Ability>().Use(transform.position + offset);

        StopCoroutine(toColor);
        StartCoroutine(ChangeColor(p_DefaultColor, 50));
        yield return(new WaitForSeconds(attack.Cooldown));

        attack.ResetCooldown();
    }
コード例 #3
0
    private void Update()
    {
        if (p_FrozenTimer > 0)
        {
            p_Velocity     = Vector2.zero;
            p_FrozenTimer -= Time.deltaTime;
            return;
        }
        else
        {
            p_FrozenTimer = 0;
        }

        //Ability use
        for (int i = 0; i < m_Attacks.Length; i++)
        {
            PlayAttackInfo attack = m_Attacks[i];

            if (attack.IsReady())
            {
                if (Input.GetButtonDown(attack.Button))
                {
                    DecreaseHealth(attack.HealthCost);
                    p_FrozenTimer = attack.FrozenTime;
                    StartCoroutine(UseAttack(attack));
                    break;
                }
            }
            else if (attack.Cooldown > 0)
            {
                attack.Cooldown -= Time.deltaTime;
            }
        }

        // Set how hard the player is pressing movement buttons
        float forward = Input.GetAxis("Vertical");
        float right   = Input.GetAxis("Horizontal");

        //Updating the animation
        cr_Anim.SetFloat("Speed", Mathf.Clamp01(Mathf.Abs(forward) + Mathf.Abs(right)));

        //Updating velocity

        float moveThreshold = 0.3f;

        if (forward > 0 && forward < moveThreshold)
        {
            forward = 0;
        }
        if (forward < 0 && forward > -moveThreshold)
        {
            forward = 0;
        }
        if (right > 0 && right < moveThreshold)
        {
            right = 0;
        }
        if (right < 0 && right > -moveThreshold)
        {
            right = 0;
        }
        p_Velocity.Set(right, forward);
    }