// Update is called once per frame
    void Update()
    {
        GameObject bullet = null;

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            bullet = SpawningUtility.SpawnBullet(gameObject.transform.position, .6f, Vector2.up);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            bullet = SpawningUtility.SpawnBullet(gameObject.transform.position, .6f, Vector2.right);
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            bullet = SpawningUtility.SpawnBullet(gameObject.transform.position, .6f, Vector2.down);
        }
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            bullet = SpawningUtility.SpawnBullet(gameObject.transform.position, .6f, Vector2.left);
        }

        if (bullet)
        {
            PlayerScript player = GetComponentInParent <PlayerScript> ();
            if (player)
            {
                BasicProjectile projectile = bullet.GetComponent <BasicProjectile> ();
                if (projectile)
                {
                    projectile.damage = (int)((float)projectile.damage * player.damageMultiplier);
                    //Debug.Log ("bullet damage set to " + projectile.damage);
                }
            }
        }
    }
Exemple #2
0
    public void SpawnMeleeTest()
    {
        //Arrange
        var gameObject = SpawningUtility.SpawnEnemy(Vector3.zero, SpawnableEnemyTypes.TestMeleeEnemy);

        //Act
        ChargingAI chargingAI = gameObject.GetComponent <ChargingAI>();
        FleeingAI  fleeingAI  = gameObject.GetComponent <FleeingAI>();

        //Assert
        Assert.IsTrue(chargingAI != null);
        Assert.IsFalse(fleeingAI != null);
    }
    void FixedUpdate()
    {
        switch (state)
        {
        case ShootingAIStates.WAITING_TO_SHOOT:
            --nextShot;
            if (nextShot <= 0)
            {
                state = ShootingAIStates.ACQUIRING_TARGET;
            }
            break;

        case ShootingAIStates.ACQUIRING_TARGET:
            GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
            target = null;
            float nearDist = targetRange;
            for (int cntr = 0; cntr < players.Length; ++cntr)
            {
                float distance = Vector3.Distance(transform.position, players [cntr].transform.position);
                if (distance < nearDist)
                {
                    target   = players [cntr];
                    nearDist = distance;
                }
            }
            if (target)
            {
                targetDetectPosition = new Vector2(target.transform.position.x, target.transform.position.y);
                state = ShootingAIStates.PREDICT_AND_SHOOT;
            }
            break;

        case ShootingAIStates.PREDICT_AND_SHOOT:
            Vector2 targetAnticipatedPosition = PredictFuturePosition(targetDetectPosition, (Vector2)target.transform.position, 1);
            Vector2 shootDirection            = targetAnticipatedPosition - (Vector2)gameObject.transform.position;
            SpawningUtility.SpawnBullet(gameObject.transform.position, .6f, shootDirection, bulletSpeed, bulletTTL);
            state    = ShootingAIStates.WAITING_TO_SHOOT;
            nextShot = betweenShotTime;
            break;

        default:
            Debug.LogError("Shooting AI somehow entered into unknown state");
            state    = ShootingAIStates.WAITING_TO_SHOOT;
            nextShot = betweenShotTime;
            break;
        }
    }