Exemplo n.º 1
0
        private void IntroBarrageRequest(EventManager.EventMessage message)
        {
            var middleOfShip = Vector3.zero;

            middleOfShip.y = 30;
            GameObject.Instantiate(message.HazardData.Prefab, middleOfShip, Quaternion.identity);
            _audioPool.PlayAudioEvent(message.HazardData.Audio);
        }
Exemplo n.º 2
0
        private void OnCollisionEnter(Collision other)
        {
            var damageable = other.gameObject.GetComponent <IDamageable>();

            if (damageable == null)
            {
                damageable = other.gameObject.GetComponentInParent <IDamageable>();
            }

            damageable?.TakeDamage(transform.position, _hitForce);

            var particleSystem = Instantiate(particles, transform.position, Quaternion.identity);

            if (particleSystem == null)
            {
                Debug.LogError("Missing particle system prefab");
            }
            else
            {
                var systems = particleSystem.GetComponentsInChildren <ParticleSystem>();
                foreach (var s in systems)
                {
                    s.Play();
                }
            }
            _audioPool.PlayAudioEvent(_audio, transform.position);

            var ship = other.gameObject.GetComponentInParent <ShipCondition>();

            if (Physics.Raycast(transform.position, Vector3.down, out RaycastHit hit, 10f))
            {
                if (hit.collider.gameObject.GetComponent <InteractableItem>())
                {
                    Destroy(gameObject);
                    return;
                }

                if (hit.collider.gameObject.GetComponentInParent <ShipCondition>())
                {
                    var pos = hit.point;
                    if (createsHoles)
                    {
                        ContactPoint contact  = other.contacts[0];
                        Quaternion   rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);
                        var          hole     = Instantiate(holePrefab, pos, rotation);
                        hole.transform.SetParent(hit.transform);
                        hole.transform.localRotation = Quaternion.identity;
                    }
                    if (causesFire)
                    {
                        var fire = Instantiate(firePrefab, pos, Quaternion.identity);
                        fire.transform.SetParent(hit.transform);
                        fire.transform.localRotation = Quaternion.identity;
                    }
                    ship?.TakeDamage();
                }
            }

            Destroy(gameObject);
        }
Exemplo n.º 3
0
    public void Act()
    {
        FindTarget();

        if (_enemyCondition == null)
        {
            return;
        }

        var dist = Vector3.Distance(transform.position, _enemyCondition.transform.position);

        if (dist < _minDistance || dist > _maxDistance)
        {
            return;
        }

        Fire();

        foreach (var p in _particleSystem)
        {
            p.Play();
        }

        _audioPool.PlayAudioEvent(_event, transform.position);
    }
Exemplo n.º 4
0
        public void Act()
        {
            FindTarget();

            // Shoot cannonball

            EventManager.TriggerEvent("IntroDone", new EventManager.EventMessage(null));

            var rot        = _spawnPos.transform.rotation;
            var cannonBall = Instantiate(_cannonBall, _spawnPos.transform.position, Quaternion.identity);

            if (_enemyCondition)
            {
                var dir = _enemyCondition.transform.position - _spawnPos.transform.position;
                rot = Quaternion.LookRotation(dir.normalized, cannonBall.transform.up);
                cannonBall.transform.localRotation = rot;
            }

            cannonBall.GetComponent <Rigidbody>().AddForce(cannonBall.transform.forward * _cannonForce, ForceMode.Impulse);
            foreach (var p in _particleSystem)
            {
                p.Play();
            }
            _audioPool.PlayAudioEvent(_event, transform.position);
        }
Exemplo n.º 5
0
        private void OnCollisionEnter(Collision other)
        {
            var damageable = other.gameObject.GetComponent <IDamageable>();

            damageable?.TakeDamage(transform.position, _hitForce);

            var ship = other.gameObject.GetComponentInParent <ShipCondition>();

            if (ship == null)
            {
                return;
            }

            if (ship.ShipType == ShipType.Enemy)
            {
                ship.TakeDamage();
            }

            var particleSystem = Instantiate(particles, transform.position, Quaternion.identity);

            if (particleSystem == null)
            {
                Debug.LogError("Missing particle system prefab");
            }
            else
            {
                var systems = particleSystem.GetComponentsInChildren <ParticleSystem>();
                foreach (var s in systems)
                {
                    s.Play();
                }
            }
            _audioPool.PlayAudioEvent(_audio, transform.position);

            Destroy(gameObject);
        }