Пример #1
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        ProjectileEnemy  missile       = collision.gameObject.GetComponent <ProjectileEnemy>();
        GuidedProjectile guidedMissile = collision.gameObject.GetComponent <GuidedProjectile>();
        Laser            laser         = collision.gameObject.GetComponent <Laser>();
        bool             laserPassed   = true;

        if (missile)
        {
            Crash();

            if (health <= 0)
            {
                Die();
            }
        }
        if (guidedMissile)
        {
            Crash();

            if (health <= 0)
            {
                Die();
            }
        }
        if (laser && laserPassed)
        {
            Crash();
            if (health <= 0)
            {
                Die();
            }
            laserPassed = false;
        }
    }
Пример #2
0
    void Attack()
    {
        if (state != State.Grabbing)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                if (currentProjectile != null)
                {
                    currentProjectile.DestroyProjectile();
                    currentProjectile = null;
                    return;
                }
                currentProjectile = LaunchProjectile();
            }
            if (Input.GetKeyDown(KeyCode.R))
            {
                Rewind();
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) && state != State.Casting)
        {
            if (grabber.currentGrab != null)
            {
                grabber.Throw();
            }
            else
            {
                grabber.TryGrab();
            }
        }
    }
Пример #3
0
    private void Shot()
    {
        if (_betweenShot)
        {
            return;
        }

        foreach (Enemy enemy in _enemies.GameObjects)
        {
            if (Vector3.Distance(transform.position, enemy.transform.position) > _range)
            {
                continue;
            }

            GameObject projectile = Instantiate(_projectilePrefab, transform.position + Vector3.up * 1.5f, Quaternion.identity) as GameObject;
            GuidedProjectile projectileBeh = projectile.GetComponent<GuidedProjectile>();
            projectileBeh.Target = enemy.gameObject;
            StartCoroutine(ShotInterval());
            return;
        }
    }
Пример #4
0
    private void Update()
    {
        if (GetProjectilePrefab() == null)
        {
            return;
        }

        if (Time.time - lastShotTime >= shootInterval)
        {
            foreach (Monster monster in monsters)
            {
                if (Vector3.Distance(transform.position, monster.transform.position) <= shootRange)
                {
                    GuidedProjectile projectile = pool.GetNewObjectSilently() as GuidedProjectile;
                    projectile.SetTarget(monster.gameObject);

                    lastShotTime = Time.time;
                    break;
                }
            }
        }
    }