private void Start() { layerMask = (1 << 0) + (1 << 1) + (1 << 2) + (1 << 4) + (1 << 5); EnemyBulletController bulletController = bullet.GetComponent <EnemyBulletController>(); distToHitPlayer = bulletController.speed * bulletController.seconds; }
public static EnemyBulletController Create(BulletStyle bulletStyle, float bulletSpeed, Rigidbody2D playerRb, Rigidbody2D enemyRb, GameObject bulletPrefab, float minDeltaT, float maxDeltaT) { EnemyBulletController obj = null; switch (bulletStyle) { case BulletStyle.DirectDown: obj = new BulletDirectDown(); break; case BulletStyle.At45DegreesToAquarium: obj = new BulletAt45DegreesToAquarium(); break; default: return(null); } obj.bulletSpeed = bulletSpeed; obj.playerRb = playerRb; obj.enemyRb = enemyRb; obj.bulletFrequency = Random.Range(minDeltaT, maxDeltaT); obj.bulletPrefab = bulletPrefab; return(obj); }
void OnTriggerEnter2D(Collider2D collider) { if (collider.gameObject.tag == "asteroid") { AsteroidController asteroidController = collider.gameObject.GetComponent <AsteroidController> (); if (asteroidController != null) { asteroidController.Damage(1); } hit(); } else if (collider.gameObject.tag == "enemy") { EnemyController enemyController = collider.gameObject.GetComponent <EnemyController> (); if (enemyController != null) { enemyController.Destroy(); } hit(); } else if (collider.gameObject.tag == "enemy_bullet") { EnemyBulletController enemyBulletController = collider.gameObject.GetComponent <EnemyBulletController> (); if (enemyBulletController != null) { enemyBulletController.Destroy(); } hit(); } }
// Shooting bullets public void shootBullet() { EnemyBulletController p = Instantiate <EnemyBulletController>(enemyBulletPrefab); p.transform.position = this.transform.position + new Vector3(1f, 1f, 1f); p.velocity = (_player.transform.position - this.transform.position).normalized * 15.0f; }
public void Fire() { shotCounter = timeBetweenShots; EnemyBulletController newEnemyBullet = Instantiate(enemyBullet, firePoint.position, firePoint.rotation) as EnemyBulletController; GameObject tec = GameObject.Find("ImageTarget/TotalEnemyControllerObject"); newEnemyBullet.transform.parent = tec.transform; }
void InstantiateBullet() { // Play shot sfx _audioSource.PlayOneShot(ShotClip, 1f); //Instantiate revolver smoke effect Vector2 bulletSmokeEffectPos; if (IsFacingRight()) { bulletSmokeEffectPos = new Vector2(transform.position.x + 0.294f, transform.position.y + 0.063f); } else { bulletSmokeEffectPos = new Vector2(transform.position.x - 0.294f, transform.position.y + 0.063f); } Instantiate(SmokeEffect, bulletSmokeEffectPos, Quaternion.Euler(-90, 0, 0)); Vector2 bulletPos; float additionYPos; if (!_enemy.IsInjured) { additionYPos = 0.108f; } else { additionYPos = 0.064f; } if (IsFacingRight()) { bulletPos = new Vector2(transform.position.x + 0.34f, transform.position.y + additionYPos); } else { bulletPos = new Vector2(transform.position.x - 0.34f, transform.position.y + additionYPos); } EnemyBulletController bullet = Instantiate(Bullet, bulletPos, Quaternion.identity); if (bullet != null) { bullet.ScaleXValue = IsFacingRight() ? 1 : -1; } _enemy.AmountOfFiredBullets++; if (_enemy.AmountOfFiredBullets >= 2) { _enemy.IsReloading = true; _animator.SetBool("IsReloading", _enemy.IsReloading); } }
// Update is called once per frame void Update() { shotCounters -= Time.deltaTime; if (shotCounters <= 0) { shotCounters = timeBetweenShots; EnemyBulletController newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as EnemyBulletController; newBullet.bulletSpeed = bulletSpeed; } }
// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer <= 0) { EnemyBulletController newenemybullet = Instantiate(enemyBullet, enemygunspawn.position, enemygunspawn.rotation) as EnemyBulletController; newenemybullet.ebulletspeed = Ebulletspeed; timer = timeinitial; } }
private void fire() { //Function for creating and firing bullets based on its rigidbody's velocity. GameObject bullet = Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation); EnemyBulletController bControl = bullet.GetComponent <EnemyBulletController> (); bControl.enemyDamage = bulletDamage; bullet.GetComponent <Rigidbody> ().velocity = (playerPos - bullet.transform.position).normalized * bulletSpeed; Destroy(bullet, 5.0f); }
private void Awake() { if (Instance == null) { Instance = this; } else if (Instance != this) { Destroy(this); } }
// Update is called once per frame void Update() { timer -= Time.deltaTime; if (timer <= 0) { EnemyBulletController newenemybullet = Instantiate(enemyBullet, enemygunspawn.position, enemygunspawn.rotation) as EnemyBulletController; EnemyBulletController newenemybullet2 = Instantiate(enemyBullet, enemygunspawn.position + new Vector3(1, 1, 1), enemygunspawn.rotation) as EnemyBulletController; EnemyBulletController newenemybullet3 = Instantiate(enemyBullet, enemygunspawn.position + new Vector3(2, 2, 2), enemygunspawn.rotation) as EnemyBulletController; newenemybullet.ebulletspeed = Ebulletspeed; newenemybullet2.ebulletspeed = Ebulletspeed; newenemybullet3.ebulletspeed = Ebulletspeed; timer = timeinitial; } }
private void Start() { player = GameObject.Find("Henchman").gameObject; enemyRb = GetComponent <Rigidbody2D>(); playerRb = player.GetComponent <Rigidbody2D>(); walkController = EnemyWalkController.Create(walkingStyle, enemyBaseSpeed, playerRb, enemyRb); walkController.BeginWalk(); spriteRenderer = GetComponent <SpriteRenderer>(); bulletController = EnemyBulletController.Create(bulletStyle, bulletSpeed, playerRb, enemyRb, bulletPrefab, minDeltaT, maxDeltaT); gameLevelManager = FindObjectOfType <LevelManager>(); }
// ==================================================== private IEnumerator AttackCoroutine() { animator.SetBool("isMoving", false); animator.SetTrigger("shootTrigger"); isAttacking = true; lastAttackTime = MinigameTimeManager.instance.time; EnemyBulletController bullet = Instantiate <EnemyBulletController>(bulletPrefab); Vector2 direction = Vector2.right * myTransform.localScale.x; bullet.Configure(direction, null); bullet.transform.position = spawnPosition.position; while (MinigameTimeManager.instance.time < lastTryAttackTime + 0.3f) { yield return(0); } isAttacking = false; }
// Update is called once per frame void Update() { if (isFiring) { shotCounter -= Time.deltaTime; if (shotCounter <= 0) { shotCounter = timeBetweenShots; EnemyBulletController newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as EnemyBulletController; newBullet.speed = bulletSpeed; } } else { shotCounter = 0; } }
void CheckForEnemiesInRadius() { int hits = 0; Collider[] objectsInRange = Physics.OverlapSphere(transform.position, damageRadius); foreach (Collider col in objectsInRange) { if (col.gameObject.tag == "Structure") { StructureController structure = col.gameObject.GetComponent <StructureController>(); if (structure != null) { structure.TakeDamage(damage); } } else if (col.gameObject.tag == "Turret") { } else if (col.gameObject.tag == "Enemy") { EnemyBulletController enemy = col.GetComponent <EnemyBulletController>(); if (enemy != null) { float proximity = (transform.position - enemy.transform.position).magnitude; float effect = 1 - (proximity / damageRadius); float damageAmount = (damage * effect); damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage); enemy.DealDamage(damage); hits++; } } } if (hits > 0) { ExpireMe(); } }
// Update is called once per frame void Update() { shotCounter -= Time.deltaTime; if (shotCounter <= 0) { shotCounter = timeBetweenShots; EnemyBulletController newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation) as EnemyBulletController; newBullet.speed = bulletSpeed; } // bulletPattern = Random.Range (1, 5); // Debug.Log ("bulletpatter : " + bulletPattern); switch (bulletPattern) { case 1: Debug.Log("BulletPattern 1"); timeBetweenShots = Random.Range(1, 5); Debug.Log("timebetweenshots" + timeBetweenShots); bulletSpeed = Random.Range(6, 10); Debug.Log("bulletspeed" + bulletSpeed); break; case 2: Debug.Log("BulletPattern 2"); timeBetweenShots = Random.Range(1, 4); Debug.Log("timebetweenshots" + timeBetweenShots); bulletSpeed = Random.Range(7, 20); Debug.Log("bulletspeed" + bulletSpeed); break; case 3: Debug.Log("BulletPattern 3"); timeBetweenShots = Random.Range(1, 6); Debug.Log("timebetweenshots" + timeBetweenShots); bulletSpeed = Random.Range(10, 20); Debug.Log("bulletspeed" + bulletSpeed); break; case 4: Debug.Log("BulletPattern 4"); timeBetweenShots = Random.Range(1, 2); Debug.Log("timebetweenshots" + timeBetweenShots); bulletSpeed = Random.Range(12, 19); Debug.Log("bulletspeed" + bulletSpeed); break; } }