void Start() { setup(); //フリーズ条件:talk game.talkEvent.Subscribe(f => { freezed.Value = f; }).AddTo(gameObject); //フリーズ条件:GameClear game.clearEvent.Subscribe(f => { if (f) { freezed.Value = true; animator.speed = 0; } }).AddTo(gameObject); //アニメーション遷移 FreezableUpdate.Subscribe(_ => { animator.SetFloat("YSpeed", rb2d.velocity.y); }); //横移動 this.UpdateAsObservable().Select(_ => Input.GetButton("DASH") && is_grounded.Value).Subscribe(b => speed_walk = b ? 5.0f : 3.0f); FreezableUpdate.Subscribe(_ => { input_lr.Value = enable_input ? Input.GetAxis("Horizontal") : 0; }); input_lr.Subscribe(i => { animator.SetBool("isRunning", input_lr.Value != 0); front_way = input_lr.Value != 0 ? input_lr.Value.CompareTo(0) : front_way; }); FreezableFixedUpdate.Subscribe(_ => { if (is_grounded.Value) { walk_to_lr(input_lr.Value); } else { fly_to_lr(input_lr.Value); } }); //接地判定 this.OnTriggerStay2DAsObservable().Where(c => c.tag == "Ground").ThrottleFrame(2).Subscribe(_ => is_grounded.Value = false); this.OnTriggerStay2DAsObservable().Where(c => c.tag == "Ground").Subscribe(_ => is_grounded.Value = true); is_grounded.Subscribe(i => animator.SetBool("isGrounded", i)); //ジャンプ FreezableUpdate.Where(_ => Input.GetButtonDown("Fire1")).Where(_ => is_grounded.Value).Subscribe(p => { animator.SetTrigger("Leap"); Observable.NextFrame(FrameCountType.FixedUpdate).Subscribe(_ => rb2d.AddForce(new Vector2(0, speed_jump) * rb2d.mass, ForceMode2D.Impulse)); }); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Bullet") { FreezableUpdate.First().Subscribe(_ => { animator.SetTrigger("magiced"); tag = "Ground"; }); } }
void Start() { setup(); front_way = -1; speed_walk = 1.0f; //フリーズ条件:timestop,talk Observable.CombineLatest(game.TimeStopEvent, game.talkEvent).Select(list => list.Any(b => b)).Subscribe(f => { freezed.Value = f; }).AddTo(gameObject); //時間停止 game.TimeStopEvent.Subscribe(i => { if (i) { tag = "Ground"; gameObject.layer = LayerMask.NameToLayer("Ground"); animator.enabled = false; } else { tag = "Enemy"; gameObject.layer = LayerMask.NameToLayer("Enemy"); animator.enabled = true; } }).AddTo(gameObject); //被弾 this.OnTriggerEnter2DAsObservable().Where(c => c.tag == "Bullet").Subscribe(collider => { FreezableUpdate.First().Subscribe(_ => { Instantiate(bomb, rb2d.transform.position, rb2d.transform.rotation); Destroy(gameObject); }); }); //移動 FreezableFixedUpdate.Subscribe(_ => { walk_to_lr(front_way); }); this.OnTriggerEnter2DAsObservable().Where(c => c.tag == "Ground").Subscribe(collider => { front_way = -front_way; }); }
protected new void setup() { base.setup(); animator = GetComponent <Animator>(); rb2d = GetComponent <Rigidbody2D>(); game = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>(); FreezableUpdate.Subscribe(_ => { animator.SetInteger("Front", front_way); }); freezed.Subscribe(f => { if (f) { velocity_before_stop = rb2d.velocity; rb2d.isKinematic = true; rb2d.Sleep(); } else { rb2d.isKinematic = false; rb2d.WakeUp(); rb2d.velocity = velocity_before_stop; } }); }
public GameObject bullet;//Controlに変更して汎用化? void Start() { GameController game; bool enable_input = true; setup(); animator = GetComponent <Animator>(); rb2d = GetComponent <Rigidbody2D>(); move_Control = GetComponent <Alice_Move_Control>(); game = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>(); //フリーズ条件:talk game.talkEvent.Subscribe(f => { freezed.Value = f; }).AddTo(gameObject); //フリーズ条件:GameClear game.clearEvent.Subscribe(f => { if (f) { freezed.Value = true; animator.speed = 0; } }).AddTo(gameObject); //敵に衝突してダメージ this.OnCollisionStay2DAsObservable() .Where(collision => collision.collider.gameObject.tag == "Enemy") .Subscribe(collision => this.UpdateAsObservable().First().Where(_ => !freezed.Value && !is_inbincible.Value).Subscribe(_ => { DamageTrigger.OnNext(Unit.Default); is_inbincible.Value = true; }) ); DamageTrigger.Subscribe(_ => { is_inbincible.Value = true; animator.SetTrigger("Damaged"); FreezableFixedUpdate.Skip(150).Take(1).Subscribe(__ => is_inbincible.Value = false).AddTo(this); game.life.Value--; }).AddTo(gameObject); //射撃 FreezableUpdate.Where(_ => enable_input).Where(_ => Input.GetButtonDown("Fire2")) .Subscribe(p => { var b = Instantiate(bullet, rb2d.transform.position + new Vector3(0, 0.5f), rb2d.transform.rotation); b.GetComponent <Bullet_Control>().velocity = new Vector3(move_Control.front_way * 10, 0); b.transform.parent = transform.parent; animator.SetTrigger("Shoot"); }); //時間停止 FreezableUpdate.Where(_ => enable_input).Where(_ => Input.GetButtonDown("Fire3")) .Subscribe(p => { game.try_timeStop(); }); //無敵処理 is_inbincible.Where(p => p).Subscribe(i => gameObject.layer = LayerMask.NameToLayer("Player_Invincible")); is_inbincible.Where(p => !p).Subscribe(i => gameObject.layer = LayerMask.NameToLayer("Player")); }