void spawnProjectile()
    {
        string pattern;

        if (Time.time >= spawnTime && isNearPlayer() && player != null && patterns.Length > 0)
        {
            int rand = Random.Range(0, patterns.Length);
            pattern = patterns [rand];
            Vector2 shootDirection = player.transform.position - transform.position;
            Debug.Log(projectilePatternFactory);
            projectilePatternFactory.createProjectilePattern(pattern, transform.position, shootDirection, false, this.gameObject);
        }
        spawnTime = Time.time + cooldownTime;
    }
Exemple #2
0
    public IEnumerator TestPlayerWithProjectileHit3()
    {
        GameObject gm           = (GameObject)Instantiate(Resources.Load("Tests/gamemanager"));
        var        playerPrefab = Resources.Load("Tests/player");
        GameObject player       = (GameObject)Instantiate(playerPrefab);
        int        startHealth  = 20;

        player.GetComponent <PlayerController> ().testMode = true;
        gm.GetComponent <GUIManager> ().playerController   = player.GetComponent <PlayerController> ();
        NetworkServer.Listen(7777);

        yield return(new WaitForSeconds(2));

        player.GetComponent <PlayerController> ().health = startHealth;
        ProjectilePatternFactory factory = gm.GetComponent <ProjectilePatternFactory> ();
        string  pattern        = "basicFireball";
        Vector3 startPosition  = new Vector3(5, 5, 0);
        Vector2 shootDirection = new Vector2(-1, -1);
        bool    belongToPlayer = false;

        factory.projectileFactory = gm.GetComponent <ProjectileFactory> ();
        factory.createProjectilePattern(pattern, startPosition, shootDirection, belongToPlayer, player);
        GameObject projectile = GameObject.FindGameObjectWithTag("Projectile");
        int        damage     = 19;

        projectile.GetComponent <ProjectileController> ().projectileDamage = damage;
        yield return(new WaitForSeconds(5));

        GameObject newplayer      = GameObject.FindGameObjectWithTag("Player");
        int        currHealth     = newplayer.GetComponent <PlayerController> ().health;
        int        expectedHealth = startHealth - damage;

        Assert.AreEqual(expectedHealth, currHealth);
    }
Exemple #3
0
    void spawnProjectile()
    {
        if (player == null)
        {
            player = GameObject.FindGameObjectWithTag("Player");
        }
        if (projectilePatternFactory == null)
        {
            projectilePatternFactory = GameManager.gm.gameObject.GetComponent <ProjectilePatternFactory>();
        }
        string pattern;

        if (Time.time >= spawnTime && patterns.Length > 0 && player != null)
        {
            int rand = Random.Range(0, patterns.Length);
            pattern = patterns [rand];
            Vector2 shootDirection = player.transform.position - transform.position;
            projectilePatternFactory.createProjectilePattern(pattern, transform.position, shootDirection, false, this.gameObject);
        }
        spawnTime = Time.time + cooldownTime;
    }
    [UnityTest]     /*1 Projectile to enemeyBat: enemyBat Hp=7? true;*/
    public IEnumerator ProjectTileLength3()
    {
        NetworkServer.Listen(7777);
        GameObject gm = Instantiate(Resources.Load("Tests/GameManager")) as GameObject;
        ProjectilePatternFactory factory = gm.GetComponent <ProjectilePatternFactory> ();
        string  pattern        = "basicFireball";
        Vector3 startPosition  = new Vector3(0, 0, 0);
        Vector2 shootDirection = new Vector2(0, 0);
        bool    belongToPlayer = false;

        factory.projectileFactory = gm.GetComponent <ProjectileFactory> ();
        factory.createProjectilePattern(pattern, startPosition, shootDirection, belongToPlayer, null);
        yield return(new WaitForSeconds(1));

        GameObject[] projectilesSpawned = GameObject.FindGameObjectsWithTag("Projectile");
        Assert.AreEqual(1, projectilesSpawned.Length);
    }