転んだときのアイテム獲得判定を無効

This commit is contained in:
kimura 2022-07-01 12:35:25 +09:00
parent 0de81be22e
commit d152b81aec
3 changed files with 32 additions and 29 deletions

View File

@ -256,9 +256,15 @@ namespace MyGame.Scenes.MiniGame.Scripts
} }
#endif #endif
x.enabled = false; x.enabled = false;
if (player.IsHit)
{
return;
}
switch (item.ItemType) switch (item.ItemType)
{ {
case StageItem.Type.Item1: case StageItem.Type.Item1:
item.Effect();
scoreCount.Value += item.Point; scoreCount.Value += item.Point;
player.AddCount(); player.AddCount();
break; break;

View File

@ -18,8 +18,9 @@ namespace MyGame.Scenes.MiniGame.Scripts
[SerializeField] private GameObject level3; [SerializeField] private GameObject level3;
private Animator animator; private Animator animator;
private bool isJump; private bool isJump;
private bool isPreHit; private bool isHit;
private readonly BoolReactiveProperty isHit = new BoolReactiveProperty(); public bool IsHit => isHit;
private readonly BoolReactiveProperty isHitStay = new BoolReactiveProperty();
private IDisposable hitDisposable; private IDisposable hitDisposable;
private Coroutine jumpCoroutine; private Coroutine jumpCoroutine;
private Vector3 basePos; private Vector3 basePos;
@ -27,14 +28,14 @@ namespace MyGame.Scenes.MiniGame.Scripts
private void Start() private void Start()
{ {
isHit.AddTo(this); isHitStay.AddTo(this);
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
basePos = transform.localPosition; basePos = transform.localPosition;
} }
public void Stay(bool force = false) public void Stay(bool force = false)
{ {
if (!force && isPreHit) if (!force && isHit)
{ {
return; return;
} }
@ -43,12 +44,12 @@ namespace MyGame.Scenes.MiniGame.Scripts
public void Move() public void Move()
{ {
if (isHit.Value) if (isHitStay.Value)
{ {
return; return;
} }
transform.AddPositionX(speed * Time.deltaTime); transform.AddPositionX(speed * Time.deltaTime);
if (isJump || isPreHit) if (isJump || isHit)
{ {
return; return;
} }
@ -57,7 +58,7 @@ namespace MyGame.Scenes.MiniGame.Scripts
public void Jump() public void Jump()
{ {
if (isJump || isPreHit) if (isJump || isHit)
{ {
return; return;
} }
@ -79,13 +80,13 @@ namespace MyGame.Scenes.MiniGame.Scripts
// こける // こける
public void Hit() public void Hit()
{ {
if (isPreHit) if (isHit)
{ {
return; return;
} }
SoundManager.Instance.PlaySE("se_minigame_Collide"); SoundManager.Instance.PlaySE("se_minigame_Collide");
animator?.Play("Brother_pink_FallDown"); animator?.Play("Brother_pink_FallDown");
isPreHit = true; isHit = true;
hitDisposable?.Dispose(); hitDisposable?.Dispose();
this.SafeStopCoroutine(jumpCoroutine); this.SafeStopCoroutine(jumpCoroutine);
@ -101,11 +102,11 @@ namespace MyGame.Scenes.MiniGame.Scripts
{ {
}, () => }, () =>
{ {
isHit.Value = true; isHitStay.Value = true;
this.CallWaitForSeconds(hitWaitTime, () => this.CallWaitForSeconds(hitWaitTime, () =>
{ {
isPreHit = false; isHit = false;
isHit.Value = false; isHitStay.Value = false;
Stay(); Stay();
}); });
}); });

View File

@ -20,24 +20,20 @@ namespace MyGame.Scenes.MiniGame.Scripts
public int Point => point; public int Point => point;
private void Start() public void Effect()
{ {
this.OnTriggerEnter2DAsObservable() // effect
.Subscribe(_ => switch (itemType)
{ {
// effect case Type.Item1:
switch (itemType) transform.SetLocalScale(0f);
{ if (effect != null) effect.SetActive(true);
case Type.Item1: break;
transform.SetLocalScale(0f); case Type.Obstacle:
if (effect != null) effect.SetActive(true); break;
break; default:
case Type.Obstacle: throw new ArgumentOutOfRangeException();
break; }
default:
throw new ArgumentOutOfRangeException();
}
}).AddTo(this);
} }
public void ResetItem() public void ResetItem()