- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我设法生成了敌人,但它们一直在生成。如何设置限制,避免不断生成?
我已经尝试添加 spawnLimit 和 spawnCounter 但无法让它工作。
var playerHealth = 100; // Reference to the player's heatlh.
var enemy : GameObject; // The enemy prefab to be spawned.
var spawnTime : float = 3f; // How long between each spawn.
var spawnPoints : Transform[]; // An array of the spawn points this enemy can spawn from.
function Start ()
{
// Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
InvokeRepeating ("Spawn", spawnTime, spawnTime);
}
function Spawn ()
{
// If the player has no health left...
if(playerHealth <= 0f)
{
// ... exit the function.
return;
}
// Find a random index between zero and one less than the number of spawn points.
var spawnPointIndex : int = Random.Range (0, spawnPoints.Length);
// Create an instance of the enemy prefab at the randomly selected spawn point's position and rotation.
Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
}
最佳答案
你可以使用这种计数器:
int maxEnemies = 100;
int enemiyCounter = 0;
并在 Spawn()
中添加:
if(enemiyCounter < maxEnemies){
Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
enemyCounter++;
}
代替
Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
关于javascript - 统一/如何设置敌人生成的限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41368157/
好的,这就是我的错误:'Enemy' 未在此范围内声明。错误在 map.h 文件中,即使 map.h 包含 enemy.h,如图所示 #ifndef MAP_H_INCLUDED #define MA
这个问题已经有答案了: How to make enemy follow player in pygame? (2 个回答) Enemy doesn't follow player (pygame)
我试图让我的 Canvas 游戏中的 Sprite 不断向玩家移动,直到它发生碰撞。执行此操作的相关函数是 update() 函数: Enemy.prototype.update = function
我在无休止的运行游戏中遇到了麻烦,主要是我创建的两种敌人的产卵,当我们调用函数“startDifficultyTimer”时,有时会产生两个敌人。 基本上,当我调用该函数时,游戏会在同一行生成 2 个
从性能角度来看,什么是最正确的 - 敌人和武器之间的交互算法(这里的子弹可能更正确)? 每个 Sprite 的每一个子弹都应该通过“collidesWith”方法检查碰撞情况,并在完整的敌人列表上进行
遇到了一个问题,即敌人会向玩家开火,但似乎总是开到高处或向玩家的一侧,即使玩家是静止的并且没有移动。我是不是在我的代码中做错了什么导致了这个疯狂的问题,或者它只是一个随机的烦人的错误? 为播放器使用相
我是新来的快速编程。我想使用类节点将敌人生成到随机位置。我试图搜索随机生成敌人的代码,但它似乎与我的代码无关。 这是我搜索随机生成的代码。 import SpriteKit class GameSce
我最近遇到了一些问题,只是在我正在制作的游戏中传递对对象/敌人的引用,我想知道我是否使用了错误的方法。 我的主要问题是处理敌人和物体,而其他敌人或玩家可能仍然与它们有联系。 例如,如果你有一只兔子和一
在我的 2d 游戏中,我有一个金币和铜币的概念如下: when normal enemies die ..they drop a random gold or copper coin. Now whe
我是新来的,所以我希望你能帮助我。 我正在学习制作简单的 cocos2d 游戏的教程 Ray Wenderlich's Tutorial 我在另一个游戏中实现了它,一个像涂鸦跳跃这样的跳跃游戏。 在上
我是一名优秀的程序员,十分优秀!