void Shoot(Transform _firePosition) { GameObject bulletInst = Instantiate(bulletPrefab, _firePosition.position, firePosition.rotation); bullet bullet = bulletInst.GetComponent <bullet>(); bullet.Fire(target); }
void shoot_at(Vector3 pos) { bullet b = game_zygote.Instance.alloc_bullet(this.side, this.type); b.transform.position = this.shoot_pos; b.shoot_to(pos); }
IEnumerator StartSpecial() { timer = 0f; for (int i = 0; i < bulletCount; i++) { if (tempList.Count == 0) { tempList = new List <GameObject>(justicePoints); } int removeIndex = Random.Range(0, tempList.Count); gunPosition = tempList[removeIndex].transform.position; tempList.RemoveAt(removeIndex); Quaternion shootDirection = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(Random.Range(-spread, spread), 0, Random.Range(-spread, spread)) ); GameObject bullet = Instantiate(specialAmmo, gunPosition, shootDirection) as GameObject; bullet bulletScript = bullet.GetComponent <bullet>(); bulletScript.damage = damage; bullet.GetComponent <Rigidbody>().AddRelativeForce(Vector3.forward * bulletSpeed * Random.Range(.8f, 1.2f), ForceMode.Impulse); yield return(new WaitForSeconds(specialTimer));; } }
public void OnCollisionEnter2D(Collision2D collision) { GameObject collideObj = collision.gameObject; PhotonView pv = collideObj.GetComponent <PhotonView>(); if (!pv) { return; } bool isSamePlayer = photonView.ownerId == pv.ownerId; if (collideObj.CompareTag(GameConstants.Tags.bullet)) { Debug.Log("Lily hit by " + collision.gameObject.name); bullet b = collideObj.GetComponent <bullet>(); if (isSamePlayer) { //Debug.Log("Collide with same mPlayerId" + this.mPlayerId); Physics2D.IgnoreCollision(mCollider, collision.collider); return; } Debug.Log("Bullet collision and hp is " + hp); photonView.RPC("MinusHP", PhotonTargets.All); } }
public Bullet() { image = Resources.豌豆子弹1; arrive = false; power = 20; name = bullet.普通子弹; }
// Update is called once per frame void FixedUpdate() { if (spacercounter < spacer) { spacercounter += Time.deltaTime; } if (Input.GetMouseButtonDown(0) && spacercounter >= spacer) { spacercounter = 0.0f; // Create the Bullet from the Bullet Prefab GameObject bullet = (GameObject)Instantiate( prefab, this.transform.position, this.transform.rotation); bullet bscript = bullet.GetComponent <bullet>(); //bscript.setPlayer(transform.parent.tag); Physics2D.IgnoreCollision(bullet.GetComponent <Collider2D>(), GetComponent <Collider2D>()); // Add velocity to the bullet //bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 6; // Destroy the bullet after 2 seconds //Destroy(bullet, destroytime); } }
void OnShoot(int senderId, int latency, int bulletIndex, Vector3 spawnPoint, Quaternion spawnRotation, int damage, Vector3 velocity, PhotonPlayer shootingPlayer, PhotonMessageInfo info) { //double timeSinceSpawn = PhotonNetwork.time - info.timestamp; if (shootingPlayer == PhotonNetwork.player) // if meri screen pe hi maine fire kra hai { GameObject bulletvfx = (GameObject)GameObject.Instantiate(bullets[bulletIndex], spawnPoint, spawnRotation); bullet bulletScript = bulletvfx.GetComponent <bullet>(); bulletScript.velocityOfBullet = velocity; bulletScript.bulletDamage = damage; bulletScript.senderId = senderId; //bulletScript.bulletSpeed = something } else { //print("time since bullet spawn = " + timeSinceSpawn.ToString() +" and ping received was -" + latency.ToString()) ; Vector3 offsetPosition; float lag = (float)(latency / 100); offsetPosition = (velocity * lag) * 1.5f; // 1.5 is just to offset GameObject bulletvfx = (GameObject)GameObject.Instantiate(bullets[0], spawnPoint + offsetPosition, spawnRotation); bullet bulletScript = bulletvfx.GetComponent <bullet>(); bulletScript.velocityOfBullet = velocity; bulletScript.bulletDamage = damage; bulletScript.senderId = senderId; //bulletScript.bulletSpeed = something // } }
GameObject createBullet() { if (counter >= maxBullets) { maxReached = true; } int currentBullet = counter % maxBullets; if (recycledBullets != null && recycledBullets.Count > 0) { currentBullet = (int)recycledBullets.Dequeue(); } else if (!maxReached) { bullet temp = (bullet)Instantiate(bullet, bulletHolder.transform); temp.identNumber = currentBullet; bullets[currentBullet] = temp; } if (bullets[currentBullet] == null) { bullet temp = (bullet)Instantiate(bullet, bulletHolder.transform); temp.identNumber = currentBullet; bullets[currentBullet] = temp; } bullets[currentBullet].gameObject.GetComponent <Rigidbody>().velocity.Scale(Vector3.zero); bullets[currentBullet].gameObject.GetComponent <Rigidbody>().angularVelocity.Scale(Vector3.zero); bullets[currentBullet].gameObject.SetActive(true); counter++; return(bullets[currentBullet].gameObject); }
// Start is called before the first frame update void Start() { Bullet1 = Bullet.GetComponent <bullet>(); Player_movement = player.GetComponent <player_movement>(); selected = PlayerPrefs.GetInt("Selcted"); if (selected == 1) { TimeBetweenShootCycle = 1.5f; } if (selected == 2) { TimeBetweenShootCycle = 1f; } if (selected == 4) { TimeBetweenShootCycle = 2f; } if (selected == 5) { TimeBetweenShootCycle = 0.4f; } }
public override void CmdfireInit(Vector3 position, Vector3 forwardRotation, GameObject owner) { centerObj = GameObject.Find("planet").transform; transform.position += transform.forward * fireOffset; for (int i = 0; i < cell_amount; i++) { float offset = ((i - (cell_amount / 2f)) / cell_amount) * angle; //Debug.Log(i + " : " + offset.ToString()); if (i == 19) { ; } GameObject obj = GameObject.Instantiate(cellBulletPrefab); bullet bul = obj.GetComponent <bullet>(); NetworkServer.Spawn(obj); bul.CmdfireInit(position, forwardRotation); // still buggy... //bul.transform.RotateAround( centerObj.position- bul.transform.position, offset ); bul.transform.Rotate(new Vector3(0, offset, 0)); Debug.Log(bul.transform.forward); //bul.transform.Rotate(0, offset, 0); bul.setOwner(owner); } }
public override void attack(int i) { bullet newBullet = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as bullet; Vector3 direction = p.transform.position - transform.position; newBullet.rb.AddForce(direction * BulletSpeed); }
void OnTriggerEnter(Collider collider) { if (collider.gameObject.tag == "Tower") { Destroy(this.gameObject); //agent.Stop(); } if (collider.gameObject.tag == "Playermob") { walk = false; attack = true; MinionStatus m = collider.gameObject.GetComponent <MinionStatus>(); Damages(m.ATK); if (m.HP <= 0) { walk = true; attack = false; } } if (collider.GetComponent <bullet>()) { bullet b = collider.GetComponent <bullet>(); Damages(b.Damagee); } }
// default bullet shooting behavior void UpdateGunDefault() { if (Input.GetAxisRaw("Fire") == 0) { // if you let go of the fire button you can fire again as soon as you press trigger again m_timeLastFire = 0; } else if (Time.time - m_timeLastFire > TimeBetweenBullets) { // keep track of when we fired so we know when to fire again m_timeLastFire = Time.time; // spawn the bullet, and set its position and velocity bullet newBullet = Instantiate(BulletPrefab); newBullet.SetVelocity(new Vector2(m_isFacingRight ? BulletSpeed : -BulletSpeed, 0)); newBullet.transform.position = m_tranMuzzle.position; m_audio.PlayOneShot(FireSound, 0.4f); Camera.main.GetComponent <CameraFollow>().ScreenShakeUntil(Time.time + ScreenShakeTime); } }
public void PlayerKillBy(GameObject player, bullet hitBullet) { string killString = "killed by " + hitBullet.getOwnerName(); NetworkPlayer p = player.GetComponent <NetworkPlayer>(); if (player.name == hitBullet.getOwnerName()) { killString = "You suicided!"; p.point--; } else { NetworkPlayer killerPlayer = hitBullet.getOwner().GetComponent <NetworkPlayer>(); killerPlayer.RpcKillNotify("You killed " + player.name); killerPlayer.point++; killerPlayer.kill_count++; if (!mResult) { if (killerPlayer.point >= winningPoints) { OnReceiveMessageFromClient("////////////////////////"); OnReceiveMessageFromClient("Player : " + killerPlayer.name + " win"); OnReceiveMessageFromClient("////////////////////////"); mResult = true; } } } p.death_count++; p.RpcGotHit(killString); UpdateScoreboard(); }
public bullet alloc_bullet(int side, int type) { GameObject obj = null; bullet b = null; switch (type) { case (int)TowerType.Normal: obj = GameObject.Instantiate(this.normal_bullet_prefab); obj.transform.SetParent(this.transform, false); b = obj.AddComponent <bullet>(); b.init(side, type, game_config.normal_tower_config.attack, game_config.normal_tower_config.speed, game_config.normal_tower_config.max_distance); break; case (int)TowerType.Main: obj = GameObject.Instantiate(this.main_bullet_prefab); obj.transform.SetParent(this.transform, false); b = obj.AddComponent <bullet>(); b.init(side, type, game_config.main_tower_config.attack, game_config.main_tower_config.speed, game_config.main_tower_config.max_distance); break; } if (b) { this.tower_bullets.Add(b); } return(b); }
private void Awake() { myrigidbody = GetComponent <Rigidbody2D>(); animator = GetComponent <Animator>(); sprite = GetComponentInChildren <SpriteRenderer>(); bullet = Resources.Load <bullet>("bullet"); }
// Update is called once per frame void Update() { RaycastHit hit; shootingTimer -= Time.deltaTime; enemyspawntimer -= Time.deltaTime; if (enemyspawntimer <= 0f) { enemyspawntimer = enemyspawningcooldown; GameObject enemyObject = Instantiate(enemyprefab); float randomangle = Random.Range(0, Mathf.PI * 2); enemyObject.transform.position = new Vector3(gamecamera.transform.position.x + Mathf.Cos(randomangle) * enemyspawningdistance, 0, gamecamera.transform.position.z + Mathf.Sin(randomangle) * enemyspawningdistance); enemy enemy1 = enemyObject.GetComponent <enemy> (); enemy1.direction = (gamecamera.transform.position - enemy1.transform.position).normalized; enemy1.transform.LookAt(Vector3.zero); } if (Physics.Raycast(gamecamera.transform.position, gamecamera.transform.forward, out hit)) { Debug.Log("1"); if (hit.transform.tag == "enemy" && shootingTimer <= 0f) { GameObject bulletobject = Instantiate(bulletprefab); bulletobject.transform.position = gamecamera.transform.position; shootingTimer = shootingcooldown; bullet bullet1 = bulletobject.GetComponent <bullet> (); bullet1.direction = gamecamera.transform.forward; bullet1.transform.LookAt(Vector3.zero); } } }
void Start() { // Get the pewsound script from the pewSound gameObject my_pewSound_script = pewSoundObject.GetComponent <pewSound>(); // Get the bullet script from the bullet gameObject my_bullet_script = prefabSphere.GetComponent <bullet>(); }
public void bulletCountUp(bullet obj) { objPool.bulletObjPool.ReturnObject(obj); bulletCount += 1; curInstantiateCount -= 1; Debug.Log("현재 파괴된 총알의 개수는 " + bulletCount + "입니다"); }
private void CreateBullet() { float _bulletCount; if (bigBullets) { _bulletCount = 4; } else { _bulletCount = 1; } GameObject _b; float _bulletAngle = 360 / _bulletCount; for (int _count = 0; _count < _bulletCount; _count++) { float _angle = bulletSpawnPoint.transform.rotation.eulerAngles.z; _angle += (_count * _bulletAngle); Vector2 _offset = Helper.MakeDistanceCoords(0.1f, _angle, _angle); _b = Instantiate(enemybullet, bulletSpawnPoint.transform.position + (Vector3)_offset, bulletSpawnPoint.transform.rotation); bullet _bb = _b.GetComponent <bullet>(); _bb.parent = gameObject; _bb.SetSpeed(MM.angle, MM.speed); } }
// Update is called once per frame private void OnTriggerEnter2D(Collider2D collision) { string layername = LayerMask.LayerToName(collision.gameObject.layer); if (!layername.Equals("bullet(Player)")) { return; } Transform playerBulletTransform = collision.transform.parent; bullet bullet = playerBulletTransform.GetComponent <bullet>(); hp = hp - bullet.power; Destroy(collision.gameObject); if (hp <= 0) { FindObjectOfType <Score>().AddPoints(points); Explosion(); Destroy(gameObject); } else { GetAnimator().SetTrigger("Damage"); } }
public void bullet_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { for (int i = 0; i < changable_item.Length; i++) { bullet item1 = changable_item[i]; e.Graphics.FillRectangle(item1.pen, new Rectangle(new Point(item1.locationX, item1.locationY - 5), SB)); } }
// Use this for initialization void Start() { bScript = GetComponent <bullet>(); barrel = transform.GetChild(0); back = transform.GetChild(1); arm = GetComponentInParent <Rigidbody2D>(); source = GetComponent <AudioSource>(); }
// Start is called before the first frame update private void Start() { RB.velocity = transform.right * speed * speedMultiplayer; selected = PlayerPrefs.GetInt("Selcted"); bullet1 = bullet3.GetComponent <bullet>(); }
}//Update void Shoot() { //shooting logic GameObject bp = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation); bullet bScript = bp.GetComponent <bullet>(); bScript.setSprite(1); } //F
void shootAt(EnemyScript e) { GameObject BulletGO = (GameObject)Instantiate(bulletPrefab, this.transform.position, this.transform.rotation); bullet b = BulletGO.GetComponent <bullet>(); b.Target = e.transform; }
void Shoot(Collider target) { bullet b = Object.Instantiate(bullet, transform.position, transform.rotation).GetComponent <bullet>(); //### //speed,target b.Initialize(10f, damage, target); }
IEnumerator moveLaser(bullet b) { while (b != null) { b.transform.position = weaponObj.transform.position + new Vector3(101, 0, 0); yield return(new WaitForFixedUpdate()); } }
// All entities deal with their own damage, not anyone else's void OnTriggerEnter2D(Collider2D data) { GameObject _other = data.gameObject; string _otherTag = _other.tag; float _damage = 0; int score = 0; if ((_otherTag == "EnemyBullet") || (_otherTag == "PlayerBullet") || (_otherTag == "Capsule")) { bullet _otherBullet = _other.GetComponent <bullet>(); if (_otherBullet.parent == gameObject) { // we can't be hit by our own bullets return; } _damage = _otherBullet.payloadEnergy; //gameController.DestroyInstance(_other); // add an asplosion if the other thing was a capsule, otherwise do the standard bullet death sprite if (_otherTag == "Capsule") { GameObject _explo = Instantiate(enemyExplosion, _other.transform.position, _other.transform.rotation); Rigidbody2D _explorb = _explo.GetComponent <Rigidbody2D>(); _explorb.velocity = _other.GetComponent <Rigidbody2D>().velocity; score = 70; GGS.capsuleSurvived = false; } else { enemyHitSound.Play(); Instantiate(bulletDeath, _other.transform.position, _other.transform.rotation); if (_otherTag == "EnemyBullet") { score = 4; } else { if (null == cloak) { score = 8; } else { // for when big ships are implemented score = 12; } } } Destroy(_other); } // when we collide with the player ship, we're the bullet, so let them deal with it. // actioning the damage will destroy us if necessary _e.DoDamage(_damage, score); }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "Bullet") { Bullet = col.gameObject.GetComponent <bullet>(); health -= Bullet.dmg; } }
bool CanPutStaticTop(bullet b, List<bullet> list) { return list.All(lb => { if (lb.end < b.start) return true; return false; //var diff = Math.Round((double)(lb.start - b.start) * (Height - 3) / 350) - b.fs; //return diff > 0; }); }
bool CanPutScroll(bullet b, List<bullet> list) { return list.All(lb => { if (lb.end < b.start) return true; var diff = Math.Round((double)(lb.start - b.start) * Width / 400) - b.width; return diff > 0; }); }
private void Put(Bullet b) { var bt = new bullet(); bt.start = Convert.ToInt32(Math.Round(Convert.ToDouble(b.start) * 100)); bt.fs = Convert.ToInt32(b.size); bt.data = b; bt.width = bt.fs * b.content.Length; Enum.TryParse(b.type, out bt.type); int defaultRow = 1; Dictionary<int, List<bullet>> s = scrolls; bt.end = bt.start + 400; if (bt.type == BulletType.Static_Bottom) { s = staticsBottom; defaultRow = Height - bt.fs - 3; bt.end = bt.start + 350; } else if (bt.type == BulletType.Static_Top) { s = staticsTop; bt.end = bt.start + 350; } bt.row = defaultRow; if (s.Any()) { List<bullet> list; bool put = false; foreach (var pair in s) { list = pair.Value; //if (s.TryGetValue(bt.row, out list)) //{ switch (bt.type) { case BulletType.Scroll: put = CanPutScroll(bt, list); break; case BulletType.Static_Bottom: put = CanPutStaticBottom(bt, list); break; case BulletType.Static_Top: put = CanPutStaticTop(bt, list); break; } if (put) { bt.row = pair.Key; list.Add(bt); break; } //} } if (!put) { var pair = s.Last(); if (bt.type == BulletType.Static_Bottom) { int next = pair.Key - bt.fs - 1; if (next > 0) bt.row = next; } else { int next = pair.Key + bt.fs + 1; if (next < Height) bt.row = next; } if (!s.TryGetValue(bt.row, out list)) { list = new List<bullet>(); list.Add(bt); s.Add(bt.row, list); } else { list.Add(bt); } } } else { var list = new List<bullet>(); list.Add(bt); s.Add(bt.row, list); } bullets.Add(bt); }