public bool Shoot() { bool ret = false; if (timer_before_new_shoot.ReadTime() > time_before_new_shoot) { if (path != null && GetBulletsCount() > 0) { EntityPathInstance.PathPoint point = path.GetPathPointFromEntityGo(gameObject); EntityBullet.EntityBulletType type = GetNextBullet(); GameObject bullet = InstantiateBulletGoFromBulletType(type); EntityBullet bullet_script = bullet.AddComponent <EntityBullet>(); bullet_script.Init(this, LevelCreatorEditor.Instance.GetBulletsSpeed(), type); RemoveNextBullet(); timer_before_new_shoot.Start(); EventManager.Event ev = new EventManager.Event(EventManager.EventType.ENTITY_SHOOTS); ev.entity_shoots.entity = this; EventManager.Instance.SendEvent(ev); ret = true; } } return(ret); }
public override void Shoot() { if (!canFire()) { return; } // Figure out the angle the bullet will be shot in // Angle = Spread + Turret Rotation float angleSpread = Random.Range(-BulletSpread / 2, BulletSpread / 2); float currentTurretRotation = this.transform.rotation.eulerAngles.y; Quaternion BulletRotation = Quaternion.Euler(0f, angleSpread + currentTurretRotation, 0f); // Figure out the speed the bullet will travel at // Speed = Parent's Velocity * Velocity Inheritance factor + Projectile Base Speed Vector3 parentVelocityVector = SpeedInheritanceFactor * this.transform.parent.parent.GetComponent <Rigidbody>().velocity; // The base velocity vector is simply a vector of BulletSpeed magnitude in the forward direction of this (the turret) object Vector3 projectileBaseVelocityVector = BulletRotation * Vector3.forward * BulletSpeed; // Instantiate the projectile // Again, ONLY for projectile based weaponry // Lasers will need special treatment. EntityBullet Bullet = (EntityBullet)Instantiate(Projectile, this.transform.position, BulletRotation); // Tell the Bullet when it's time to disappear Bullet.TimeToDeath = Time.timeSinceLevelLoad + BulletLifetime; Bullet.ignoreObject = this.transform.parent.parent; // Change the Bullet Rigidbody's speed Rigidbody BulletRigidbody = Bullet.GetComponent <Rigidbody>(); BulletRigidbody.AddForce(parentVelocityVector + projectileBaseVelocityVector, ForceMode.VelocityChange); }
private void Shoot(Entity target) { //stocker la balle créer GameObject bullet = Instantiate(prefabBullet, pointSpawn.position, pointSpawn.rotation); //récupère le component EntityBullet entity = bullet.GetComponent <EntityBullet>(); entity.SetDamage(damageAttack); entity.SetTarget(target); }
void OnCollisionEnter(Collision col) { float damage = 10f; // CHANGE ME if (col.gameObject.GetComponent <EntityBullet>()) { EntityBullet bullet = (EntityBullet)col.gameObject.GetComponent <EntityBullet>(); if (bullet.ignoreObject == this.transform || this.transform.IsChildOf(bullet.ignoreObject)) { return; } damage = bullet.damage; //Debug.Log ("Collided with bullet"); } else { //Debug.Log ("Something else"); } ShieldHit(col.contacts[0].point, damage); }
public void OnHit(EntityBullet entityBullet) { Debug.Log("Foobar"); }