我真的是React的新手。我正在开发一个工作网站,并且在以下方面苦苦挣扎,希望能获得任何帮助。
我有一个人员列表,每条记录上都有按钮,这些按钮可以用于签入或签出该人员,也可以分别将其取消。由于状态已正确更新,并且使用axios将数据传递到了Firebase,因此在Redux方面一切正常。我在顶部有一个进度条,它更新了签入的人数并更新了更改,但是个人没有更新以显示新的正确详细信息。我希望我的解释有意义。
我的代码如下:
GuestItem.js
private void OnTriggerEnter(Collider other)
{
switch (gameObject.tag)
{
case "Player":
{
if (other.CompareTag("Asteroid"))
{
if (playerController.HasShield())
{
Destroy(other.gameObject); // Asteroid
Instantiate(asteroidExplosion, other.transform.position, other.transform.rotation);
playerController.RemoveShield();
}
else
{
Destroy(other.gameObject); // Asteroid
Destroy(gameObject); // Player
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
}
if (other.CompareTag("Enemy"))
{
if (playerController.HasShield())
{
Destroy(other.gameObject); // Enemy
Instantiate(enemyExplosion, other.transform.position, other.transform.rotation);
playerController.RemoveShield();
}
else
{
Destroy(other.gameObject); // Enemy
Destroy(gameObject); // Player
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
}
if (other.CompareTag("BoltEnemy"))
{
if (playerController.HasShield())
{
Destroy(other.gameObject); // BoltEnemy
playerController.RemoveShield();
}
else
{
Destroy(other.gameObject); // BoltEnemy
Destroy(gameObject); // Player
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
}
if (other.CompareTag("Boss"))
{
// if player ship hits the boss, player gets destroyed, no matter if he has a shield left or not
if (playerController.HasShield())
{
playerController.RemoveShield();
}
Destroy(gameObject); // Player
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.GameOver();
}
if (other.CompareTag("PowerUpBolt"))
{
Destroy(other.gameObject); // PowerUpBolt
audioPowerUp.Play();
playerController.IncreaseShotSpawns();
}
if (other.CompareTag("PowerUpHealth"))
{
Destroy(other.gameObject); // PowerUpHealth
audioPowerUp.Play();
if (!playerController.HasShield())
{
playerController.AddShield();
}
}
}
break;
case "Asteroid":
{
if (other.CompareTag("BoltPlayer"))
{
Destroy(other.gameObject); // BoltPlayer
Destroy(gameObject); // Asteroid
Instantiate(asteroidExplosion, other.transform.position, other.transform.rotation);
gameController.AddScore(scoreValueAsteroid);
}
}
break;
case "Enemy":
{
if (other.CompareTag("BoltPlayer"))
{
Destroy(other.gameObject); // BoltPlayer
Destroy(gameObject); // Enemy
Instantiate(enemyExplosion, other.transform.position, other.transform.rotation);
gameController.AddScore(scoreValueEnemy);
gameController.SpawnPowerUp(other.transform);
}
}
break;
case "Boss":
{
if (other.CompareTag("BoltPlayer"))
{
Destroy(other.gameObject); // BoltPlayer
bossController.GotHit();
if (bossController.IsDefeated())
{
Destroy(gameObject); // Boss
Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
gameController.Success();
}
}
}
break;
}
}
Checkin.js
const GuestItem = props => {
const styleObj = {
fontSize: 14,
color: "mediumseagreen",
fontWeight: 800
}
return (
<div className={classes.Guest_item}>
<div>
{props.visibility && (
<div className={classes.Alert}>
<p><strong>{props.alert}</strong></p>
</div>
)}
</div>
<div className={classes.Guest_item__content}>
<div className={classes.Guest_item__info} key={props.key}>
<p><strong>{props.firstName} {props.lastName}</strong></p>
<p>Total Guests Attending: {props.pax}</p>
{props.checked > 0 && (<p style={styleObj}>Total Guests Checked In: {props.checked}</p>)}
</div>
<button
onClick={props.in}
>
<FontAwesomeIcon icon="user-check"></FontAwesomeIcon>
</button>
<button
onClick={props.out}
>
<FontAwesomeIcon icon="user-times"></FontAwesomeIcon>
</button>
<button
onClick={props.cancel}
>
<FontAwesomeIcon icon="user-slash"></FontAwesomeIcon>
</button>
</div>
</div>
);};
export default connect(null)(GuestItem);