【发布时间】:2019-09-24 08:09:53
【问题描述】:
我正在尝试在我的游戏中实现一个通电系统,但不知道如何实现它。到目前为止,我有一个 powerup spawner,它在随机位置实例化一个 powerup 预制件。一旦被捡起,它就会自我毁灭并在另一个位置生成。所有权力都使用同一个预制件,并且一次在地图上只有一个。
spawnLocations = GameObject.FindGameObjectsWithTag("spawnLocation");
Instantiate(powerup, spawnLocations[spawnRandom].transform.position, transform.rotation);
至于通电,在拾取时应该移除当前的通电(如果玩家有)并用随机选择的新通电替换它。 (不需要计时器)。
我做了几个简单的通电:
public void SpeeedBoost(float speedMultiplied) {
var playerController = gameObject.GetComponent<PlayerController>();
playerController.speed = playerController.speed * speedMultiplied;
}
public void JumpBoost(float jumpPower) {
var playerJump = gameObject.GetComponent<PlayerJump>();
playerJump.jumpSpeed = playerJump.jumpSpeed * jumpPower;
}
+ 可能换个武器等等。
他们应该这样称呼:
private void OnTriggerEnter2D(Collider2D collision) {
if (collision.gameObject.tag == "powerup") {
// Remove current powerup and call a new random one
}
}
所以我需要一些帮助。我应该如何构建我的通电?我如何随机调用它们?考虑可能以某种方式使用 unityEvent 。或者也许将每个通电保存为带有自己脚本的预制件并交换它们(虽然感觉有点乱)。
我在这里有点迷路,任何建议/示例都表示赞赏。 :)
【问题讨论】: