コード例 #1
0
    private void OneWayShot()
    {
        ProjectileBehaviour projectileBehaviour = InitProjectile();

        projectileBehaviour.Init(Tags.PLAYER_PROJECTILE, shipDefiniton, Vector3.right,
                                 Quaternion.Euler(0, 0, -90));
    }
コード例 #2
0
 private void ThreeWayShot()
 {
     for (int i = 0; i < projectileDir.Length; i++)
     {
         ProjectileBehaviour projectileBehaviour = InitProjectile();
         projectileBehaviour.Init(Tags.PLAYER_PROJECTILE, shipDefiniton, projectileDir[i],
                                  Quaternion.Euler(0, 0, -90));
     }
 }
コード例 #3
0
    public void Shot()
    {
        ProjectileBehaviour projectileBehaviour =
            (ProjectileBehaviour)ResourceManager.SpawnFromPool(LevelManager.ProjectileDefinitionPool.ID,
                                                               transform.position,
                                                               Quaternion.identity);

        projectileBehaviour.Init(Tags.ENEMY_PROJECTILE, ShipDefinition, Vector3.left, Quaternion.Euler(0, 0, 90));
    }
コード例 #4
0
    private void Fire()
    {
        current_time = current_time - attack_speed;

        ProjectileBehaviour bullet = GameObject.Instantiate(projectile_template);

        bullet.transform.position = tower_turret.transform.position;
        bullet.Init(_projectile, _target.transform, _damage);
    }
コード例 #5
0
    void Update()
    {
        // Update nearest target
        DamageReceiver target = GetNearestTarget();

        if (target == null)
        {
            return;
        }

        if (_shootState != ShootState.Shooting)
        {
            // Rotate forward vector towards target
            Vector3 d = target.DamageTarget.transform.position - Gimbal.transform.position;
            Vector3 f = Vector3.RotateTowards(Gimbal.transform.forward, d, GimbalRotationSpeed * Time.deltaTime, 0);
            Gimbal.transform.rotation = Quaternion.LookRotation(f);
        }

        // Shooting
        // ShootStateCoroutine is not ready
        if (_shootState != ShootState.Ready)
        {
            return;
        }

        // Gimbal is aiming too far from target
        if (Vector3.Angle(Gimbal.transform.forward, target.DamageTarget.transform.position - Gimbal.transform.position) > MaxShootAngle)
        {
            return;
        }

        ProjectileBehaviour projectile = Instantiate(Projectile, ProjectileSpawn.transform.position, Gimbal.transform.rotation)
                                         .GetComponent <ProjectileBehaviour>();

        if (projectile == null)
        {
            throw new Exception("Projectile does not have 'ProjectileBehaviour' component.");
        }

        // Pass information to projectile
        projectile.Init(Alignment, target, ShootDuration);
        _shootState = ShootState.Shooting;

        // Start ShootStateCoroutine
        StartCoroutine(ShootStateCoroutine());
    }