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)); }); }
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")); }