Beispiel #1
0
    // get a random point on a circle with given radius
    private float3 RandomPointOnCircle(float radius)
    {
        Vector2 randomPoint = Random.insideUnitCircle.normalized * radius;

        // return random point on circle, centered around the player position
        return(new float3(randomPoint.x, 0.5f, randomPoint.y) + (float3)GameManagerNonECS.GetPlayerPosition());
    }
Beispiel #2
0
    // turn to face the player's position
    private void FacePlayer()
    {
        Vector3 playerPosition = GameManagerNonECS.GetPlayerPosition();

        Vector3 direction = playerPosition - transform.position;

        direction.y = 0f;

        transform.rotation = Quaternion.LookRotation(direction, Vector3.up);
    }
Beispiel #3
0
    void Update()
    {
        // move forward
        MoveForward();

        // if game is playing, turn to crash into the player
        if (!GameManagerNonECS.IsGameOver())
        {
            FacePlayer();
            CheckPlayerCollision();
            CheckBulletCollisions();
        }
    }
Beispiel #4
0
    // loop through all the bullets and check proximity
    private void CheckBulletCollisions()
    {
        GameObject[] allBullets = GameObject.FindGameObjectsWithTag("Bullet");

        foreach (GameObject bullet in allBullets)
        {
            if (Vector3.Distance(bullet.transform.position, transform.position) < collisionDistance)
            {
                Destroy(gameObject);
                Destroy(bullet.gameObject);
                FXManager.Instance.CreateExplosion(transform.position);
                GameManagerNonECS.AddScore(1);
            }
        }
    }
Beispiel #5
0
    // simple Singleton
    void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }


        player       = FindObjectOfType <PlayerManager>().transform;
        enemySpawner = FindObjectOfType <EnemySpawnerNonECS>();

        gameState = GameState.Ready;
    }
Beispiel #6
0
    // check proximity to player
    private void CheckPlayerCollision()
    {
        Vector3 playerPosition = GameManagerNonECS.GetPlayerPosition();

        playerPosition.y = transform.position.y;
        if (Vector3.Distance(playerPosition, transform.position) < collisionDistance)
        {
            Destroy(gameObject);
            FXManager.Instance.CreateExplosion(transform.position);

            // player is invincible by default in this non-ECS version of the demo
            if (canHitPlayer)
            {
                FXManager.Instance.CreateExplosion(playerPosition);
                GameManagerNonECS.EndGame();
            }
        }
    }
Beispiel #7
0
    private void Update()
    {
        // disable if the game has just started or if player is dead
        if (!canSpawn || GameManagerNonECS.IsGameOver())
        {
            return;
        }

        // count up until next spawn
        spawnTimer += Time.deltaTime;

        // spawn and reset timer
        if (spawnTimer > spawnInterval)
        {
            SpawnWave();
            spawnTimer = 0;
        }
    }