【发布时间】:2021-10-10 23:41:24
【问题描述】:
我想统计与碰撞器的碰撞次数,从现在开始我该怎么做?
detectflags.cs
public bool IsReceive=false;
public void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("MolotovCocktail"))
{
IsAttack.Value = true;
}
if (other.gameObject.CompareTag("Weapon")||other.gameObject.CompareTag("MolotovCocktail"))
{
IsReceive = true;
}
}
CountNumber.cs
public GameObject slimeChild;
private void GamaOverDecision()
{
if (slimeChild.GetComponent<ChildrenSlimeWeaponCollider>().IsReceive == true)
{
var SlimeCount = 0;
++SlimeCount;
if (SlimeCount == 5)
{
gameOverPopUp.GetComponent<GameOverPopUp>().SetView();
}
}
}
【问题讨论】:
-
你听说过Observer Pattern吗?
-
@nIcEcOw 我从未听说过。如果可能的话,我想在这两个脚本中解决它。