public override void update(float dt, double update_time) { if (is_held_) { return; } if (MyCollider.isDisabledBullet(collider_) && update_time - start_ > 0.1) { MyCollider.disableForBullet(collider_, false); } var collider_type = MyCollider.getHitOpponentForBullet(collider_); if (collider_type != MyCollider.Type.None) { if (collider_type == MyCollider.Type.EnemyHoming) { Vector3 target; MyCollider.getHitOpponentInfoPositionForBullet(collider_, out target); var diff = target - rigidbody_.transform_.position_; Vector3.Normalize(diff); const float speed = 10f; diff *= speed; rigidbody_.setVelocity(ref diff); } else { Spark.Instance.spawn(ref rigidbody_.transform_.position_, Spark.Type.Bullet, update_time); destroy(); return; } } if (rigidbody_.transform_.position_.y < 0f) { WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_, 0.5f /* value */, 1f /* size */); destroy(); var pos = new Vector3(rigidbody_.transform_.position_.x, -0.5f, rigidbody_.transform_.position_.z); for (var i = 0; i < 8; ++i) { var spread = 2f; var vel = new Vector3(Mathf.Cos(i * Mathf.PI * (2f / 8f)) * spread, MyRandom.Range(5f, 7f), Mathf.Sin(i * Mathf.PI * (2f / 8f)) * spread); WaterSplash.Instance.spawn(ref pos, ref vel, update_time); } return; } prev_position_ = rigidbody_.transform_.position_; rigidbody_.update(dt); MyCollider.updateBullet(collider_, ref rigidbody_.transform_.position_); if (update_time - start_ > MyRandom.Range(2f, 2.5f)) // 寿命 { destroy(); return; } }
public void init(ref Vector3 position, ref Quaternion rotation) { base.init(); rigidbody_.init(ref position, ref rotation); collider_ = MyCollider.createBullet(); MyCollider.initSphereBullet(collider_, ref position, 0.25f /* radius */); MyCollider.disableForBullet(collider_, true); is_held_ = true; start_ = 0; beam_id_ = Beam.Instance.spawn(0.25f /* width */, Beam.Type.Bullet); }