Beispiel #1
0
        /// <summary>
        /// Called when an object stop touching the collider.
        /// </summary>
        /// <param name="other">The other's game object collider.</param>
        void OnTriggerExit(Collider other)
        {
            GameObjectController.Destroy(other.gameObject, true);

            Debug.Log(string.Format("Destroyed By World Boundary {3} - Position ({0},{1},{2}", other.transform.position.x, other.transform.position.y,
                                    other.transform.position.z, other.gameObject.name));
        }
Beispiel #2
0
        private void SwarmEnemy()
        {
            _spawnDeltaTime    -= Time.deltaTime;
            _timeBetweenSpawns -= Time.deltaTime;

            var number = _random.Next(-5, 5);


            if (_spawnDeltaTime <= 0 && EnemiesSpawnedPerSwarm < EnemiesPerSwarm && _totalEnemiesSwarmed < TotalNumEnemies)
            {
                var spawnPosition = new Vector3(Random.Range(-SpawnValues.position.x, SpawnValues.position.x),
                                                SpawnValues.position.y, SpawnValues.position.z);

                if (number > 0)
                {
                    GameObjectController.Instantiate(PurpleEnemy, spawnPosition, Quaternion.identity);
                }
                else
                {
                    GameObjectController.Instantiate(RedEnemy, spawnPosition, Quaternion.identity);
                }

                EnemiesSpawnedPerSwarm++;
                _totalEnemiesSwarmed++;
                _spawnDeltaTime = SpawnTime;
            }

            if (_timeBetweenSpawns <= 0)
            {
                EnemiesSpawnedPerSwarm = 0;
            }
        }
Beispiel #3
0
        void FireInFormation()
        {
            if (!_swarmFormation.InFormation)
            {
                return;
            }

            GameObjectController.Instantiate(Shot, ShotSpawn.position, ShotSpawn.rotation);
            audio.Play();
        }
Beispiel #4
0
        /// <summary>
        /// Updates every frame our scene.
        /// </summary>
        private void Update()
        {
            if (GameObjectController.IsConnected() && !networkView.isMine)
            {
                enabled = false;
                return;
            }

            if (Input.GetKeyDown(KeyCode.T) && Time.time > _nextFire)
            {
                _nextFire = Time.time + FireRate;
                var clone = GameObjectController.Instantiate(Shot, ShotSpawn.position, ShotSpawn.rotation, ignoreServerCheck: true);
                audio.Play();
            }
        }
Beispiel #5
0
        private void Update()
        {
            if (GameObjectController.IsConnected() && !Network.isServer)
            {
                return;
            }

            if (!Spline.End)
            {
                gameObject.transform.position = Spline.GetPosition();
                Spline.Update(Time.deltaTime);
            }
            else
            {
                InFormation = true;
            }
        }
Beispiel #6
0
        private void OnTriggerEnter(Collider other)
        {
            if (other.tag.Equals("WorldBoundary") || other.tag == "Enemy" || other.tag == "EnemyRed" || other.tag == "EnemyBolt")
            {
                return;
            }

            try
            {
                if (other.tag.Equals("Player") && (gameObject.tag.Equals("EnemyBolt") || gameObject.tag.Equals("Enemy") || gameObject.tag.Equals("EnemyRed")))
                {
                    GameObjectController.Instantiate(PlayerExplosion, other.transform.position, other.transform.rotation);
                    //GameObjectController.Destroy(gameObject);
                    //GameObjectController.Destroy(other.gameObject);
                    Debug.Log(string.Format("Destroyed By Contact - {0} Collided with {1}", gameObject.name, other.gameObject.name));
                    _gameControllerObject.IsPlayerAlive = false;
                }

                Debug.Log(other.name);

                if ((gameObject.tag.Equals("Enemy") || gameObject.tag.Equals("EnemyRed")) && other.tag.Equals("Bolt"))
                {
                    _gameControllerObject.EnemiesKilled++;
                    _gameControllerObject.AddScore(ScoreValue);
                }

                if (Explosion != null)
                {
                    GameObjectController.Instantiate(Explosion, transform.position, transform.rotation);
                }


                GameObjectController.Destroy(gameObject);
                GameObjectController.Destroy(other.gameObject);
                Debug.Log(string.Format("Destroyed By Contact - {0} Collided with {1}", gameObject.name, other.gameObject.name));
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
            }
        }
Beispiel #7
0
        /// <summary>
        /// This method is called automatically by unity at each physics step. Code executed once per physics step.
        /// </summary>
        void FixedUpdate()
        {
            if (GameObjectController.IsConnected() && !networkView.isMine)
            {
                return;
            }

            //I'm only using the horizontal component. GetAxis returns only 0-1, so movement is per unit.
            var moveHorizontal = Input.GetAxis("Horizontal");


            var movement = new Vector3(moveHorizontal, 0, 0);

            rigidbody.velocity = movement * Speed;

            rigidbody.position = new Vector3(
                Mathf.Clamp(rigidbody.position.x, Boundary.Xmin, Boundary.Xmax),
                0,
                0
                );

            rigidbody.rotation = Quaternion.Euler(.0f, .0f, -rigidbody.velocity.x * Tilt);
        }
Beispiel #8
0
 public void SpawnPlayer()
 {
     GameObjectController.Instantiate(Player1, new Vector3(0, 0), Quaternion.identity, 0);
     IsPlayerAlive = true;
 }