//called by animation event when the visual is ready to fire private void actuallyFire() { BulletEnemy bullet = Instantiate <BulletEnemy>(projectileRef); float angle = transform.eulerAngles.z + shootingAngle; bullet.init(transform.position, angle); }
// Start is called before the first frame update private void Start() { _anim = GetComponentInChildren <Animator>(); _sprite = GetComponentInChildren <SpriteRenderer>(); bullet = bulletPrefab.GetComponent <BulletEnemy>(); _currentTarget = pointA.position; }
//handle collisions with 'trigger' entities (that can be passed through) private void OnTriggerEnter2D(Collider2D otherCol) { //Check if collide with enemy if (otherCol.gameObject.layer == Alias.LAYER_ENEMIES) { if (pc.currState != PCController.State.slamming) { EnemyCollManager enemyColl = otherCol.gameObject.GetComponent <EnemyCollManager>(); EnemyInfo enemyCollided = otherCol.gameObject.GetComponent <EnemyInfo>(); enemyColl.onCollidedByPC(); if (OnHit != null) { OnHit(enemyCollided.damageOnContact); } } //depending on the enemy type and state (e.g. is it in fire state?) the PC can be more or less damaged, knocked back, etc. } else if (otherCol.gameObject.layer == Alias.LAYER_ENEMY_PROJECTILES) { BulletEnemy bullet = otherCol.gameObject.GetComponent <BulletEnemy>(); bullet.onHitPC(); if (OnHit != null) { OnHit(bullet.damage); } } }
private void OnTriggerEnter2D(Collider2D collision) { BulletEnemy target = collision.GetComponent <BulletEnemy>(); if (target != null) { Destroy(collision.gameObject); } }
protected virtual void OnBeginAttack() { Vector2 dirAttack = getRotationToPlayer((TargetFire.center - PositionSpawnBullet).normalized, OffsetAngleAttack); BulletEnemy bullet = pool.Spawn(id_bul, PositionSpawnBullet, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); SetNewAction(Action.Idle); OnBeginIdle(); }
void Shoot() { Vector2 bulletDirection = player.Position - body.position; bulletDirection.Normalize(); BulletEnemy newBullet = Instantiate(bulletEnemy, body.position, Quaternion.identity); newBullet.Direction = bulletDirection; Invoke("Shoot", timeBetweenShots); }
void ShootPlayer() { if (player == null) { return; } Debug.Log("EnemyAI is shooting"); GameObject bulletObj = Instantiate(bulletPrefab, gameObject.transform.position + new Vector3(0, 0, 0.01f), Quaternion.identity); BulletEnemy bullet = (BulletEnemy)bulletObj.GetComponent <BulletEnemy>(); bullet.setDirection(player.transform.position - gameObject.transform.position); bullet.setSpeed(Globals.ENEMY_SHOOTER_BULLET_SPEED); }
// Update is called once per frame void Update() { timeActive += Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, target.position, (enemySpeed * Time.deltaTime)); if (randomBulletTime >= timeActive && hasShot == false && player != null) { BulletEnemy bullet = Instantiate(bulletPrefab); bullet.transform.position = transform.position; bullet.playerDirection = player.position; hasShot = true; } }
private void Shoot() { GameObject player = GameFlow.Instance.player; GameObject bulletObj = Instantiate(bulletPrefab, gameObject.transform.position + new Vector3(0, 0, 0.01f), Quaternion.identity); BulletEnemy bullet = (BulletEnemy)bulletObj.GetComponent <BulletEnemy>(); Vector2 dirVec = player.transform.position - gameObject.transform.position; Vector2 normVec = new Vector2(dirVec.y, -dirVec.x); Vector2 randomVec = normVec * Random.Range(-0.3f, 0.3f); Vector2 totalVec = dirVec + randomVec; bullet.setDirection(totalVec); bullet.setSpeed(Globals.ENEMY_SHOOTER_BULLET_SPEED); }
private void OnTriggerEnter2D(Collider2D colli) { if (colli.gameObject.layer == Alias.LAYER_ENEMY_PROJECTILES) { print("Enemy projectile hit"); BulletEnemy bullet = colli.gameObject.GetComponent <BulletEnemy>(); bullet.onHitPC(); if (OnHitShield != null) { OnHitShield(); } pc.doShieldHit(); } }
protected virtual void OnBeginAttack() { float z = MathQ.DirectionToRotation(DirectFire).z; for (int i = -1; i <= 1; i++) { Vector2 dirAttack = MathQ.RotationToDirection(z + OffsetAngleAttack * i); BulletEnemy bullet = pool.Spawn(id_bul, PositionSpawnBullet, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); } SetNewAction(Action.Idle); OnBeginIdle(); }
private void OnTriggerEnter2D(Collider2D collision) { Enemy target = collision.GetComponent <Enemy>(); BulletEnemy target2 = collision.GetComponent <BulletEnemy>(); if (target != null) { target.TakeDamage(damage); } else if (target2 != null) { Destroy(collision.gameObject); } //Here we check what Power_Up we hit and apply it's effects }
private void Attacking() { if (!attacked && Time.time - time_start_action > 7 * time_action / 12) { float z = Random.Range(0, 60); for (int i = 0; i < 6; i++) { float zz = z + 60 * i; Vector2 dirAttack = MathQ.RotationToDirection(zz); Vector2 vitriradan = center + dirAttack * DistancePositonSpawnBull; BulletEnemy bullet = pool.Spawn(id_bul, vitriradan, MathQ.DirectionToQuaternion(dirAttack)) as BulletEnemy; DamageData dam = new DamageData(); SetUpDamageData(dam); dam.Direction = dirAttack; bullet.StartUp(dam); } attacked = true; } }
private void CreateBulletEnemyObjectInPool() { BulletEnemy go; if (bulletEnemyPooledObject == null) { go = new BulletEnemy(); } else { go = Instantiate(bulletEnemyPooledObject) as BulletEnemy; } go.gameObject.SetActive(false); PooledBulletEnemy.Add(go); if (Parent != null) { go.transform.parent = this.Parent; } else { go.transform.parent = transform; } }
// Start is called before the first frame update private void Start() { bullet = bulletPrefab.GetComponent <BulletEnemy>(); }