Beispiel #1
0
    IEnumerator CoUpdate()
    {
        while (true)
        {
            if (target == null)
            {
                yield return(null);
            }
            else
            {
                attacking = true;
            }

            if (health <= 0)
            {
                Destroy(gameObject);
                yield return(null);
            }

            // check to move forward
            if (!attacking)
            {
                transform.position += transform.forward * Time.deltaTime * speed;
            }

            // initiate attack
            else
            {
                yield return(new WaitForSeconds(0.5f));

                // attacking "animation"
                Vector3    position = transform.position;
                Quaternion rotation = transform.rotation;

                // spawn new ball
                WizardProjectile newFireball = Instantiate(fireball, position, rotation) as WizardProjectile;
                if (newFireball != null)
                {
                    newFireball.Seek(target);
                }
                yield return(new WaitForSeconds(3f));
                //attacking = false;
            }

            yield return(null);
        }
    }
    public void Shoot()
    {
        if (Time.time < m_NextAllowedShootTime)
        {
            return;
        }

        if (Character.Current == null || Vector2.Distance(Character.Current.transform.position, transform.position) > 25f)
        {
            return;
        }

        WizardProjectile projectile = Instantiate(m_ProjectilePrefab, transform.position, Quaternion.identity);

        projectile.Direction = Character.Current.transform.position - transform.position;

        m_NextAllowedShootTime = Time.time + 1 / m_ShootSpeed;
    }