add 障害物

This commit is contained in:
kimura 2022-06-20 18:28:21 +09:00
parent 0ab01fa7a3
commit 4699751029
3 changed files with 50 additions and 3 deletions

View File

@ -121,6 +121,9 @@ namespace MyGame.Scenes.MiniGame.Scripts
case StageItem.Type.Item1: case StageItem.Type.Item1:
headerView.AddCount(); headerView.AddCount();
break; break;
case StageItem.Type.Obstacle:
player.Hit();
break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using UniRx; using UniRx;
using UniRx.Diagnostics;
using UniRx.Triggers; using UniRx.Triggers;
using UnityEngine; using UnityEngine;
@ -10,14 +11,23 @@ namespace MyGame.Scenes.MiniGame.Scripts
[SerializeField] private float speed = 5f; [SerializeField] private float speed = 5f;
[SerializeField] private float jumpTime = 1.25f; [SerializeField] private float jumpTime = 1.25f;
[SerializeField] private float jumpHeight = 5f; [SerializeField] private float jumpHeight = 5f;
[SerializeField] private float hitTime = 1.5f;
[SerializeField] private float hitWaitTime = 1f;
private bool isJump; private bool isJump;
private readonly BoolReactiveProperty isHit = new BoolReactiveProperty();
private IDisposable hitDisposable;
private void Start() private void Start()
{ {
isHit.AddTo(this);
} }
public void Move() public void Move()
{ {
if (isHit.Value)
{
return;
}
transform.AddPositionX(speed * Time.deltaTime); transform.AddPositionX(speed * Time.deltaTime);
} }
@ -38,5 +48,26 @@ namespace MyGame.Scenes.MiniGame.Scripts
isJump = false; isJump = false;
}); });
} }
// こける
public void Hit()
{
hitDisposable?.Dispose();
// ジャンプが終わるのを待つ
hitDisposable = this.UpdateAsObservable().First(_ => !isJump).Debug("Hit").Subscribe(_ =>
{
this.CallLerp(hitTime, t =>
{
// transform.SetLocalPositionY(cachePos.y + Mathf.Sin(Mathf.PI * t) * jumpHeight);
}, () =>
{
isHit.Value = true;
this.CallWaitForSeconds(hitWaitTime, () =>
{
isHit.Value = false;
});
});
}).AddTo(this);
}
} }
} }

View File

@ -9,11 +9,15 @@ namespace MyGame.Scenes.MiniGame.Scripts
{ {
public enum Type public enum Type
{ {
Item1 Item1,
Obstacle,
} }
[SerializeField] private Type itemType; [SerializeField] private Type itemType;
public Type ItemType => itemType; public Type ItemType => itemType;
[SerializeField] private int point;
public int Point => point;
private void Start() private void Start()
{ {
@ -22,7 +26,16 @@ namespace MyGame.Scenes.MiniGame.Scripts
.Subscribe(_ => .Subscribe(_ =>
{ {
// effect // effect
gameObject.SetActive(false); switch (itemType)
{
case Type.Item1:
gameObject.SetActive(false);
break;
case Type.Obstacle:
break;
default:
throw new ArgumentOutOfRangeException();
}
}).AddTo(this); }).AddTo(this);
} }
} }