我目前正在制作游戏制作器中的游戏。玩家的攻击工作是获取玩家的耐力并将其存储在伤害变量中,然后飞出玩家并击中敌人,从敌人身上获得两倍于伤害变量的生命值。
如果玩家在执行攻击时耐力为 45,则 攻击精灵会以 45 的伤害飞出。击中敌人时 这将对敌人造成 90 点伤害,只剩下 10 点 健康。
问题是游戏似乎不知道哪个攻击精灵击中了敌人,因为您可以执行基本上无限数量的攻击,因此不会对敌人施加正确的伤害量。
如何获取与敌人碰撞的物体的实例 ID,以便我可以使用它来访问伤害变量?
提前致谢
我假设您正在使用与敌人的碰撞事件,对吗?在其中,您应该能够使用 other
.所以,像这样:
var instance_id = other.id
以下是YoYoGames为其他人提供的更多信息:
https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/keywords.html
这是名单上的第二个:)
下面是 Jeremy Mind 的代码示例:
触发攻击的事件(例如,全局鼠标留在玩家对象中(:
var attackInstance = instance_create(x, y, obj_attack); //Create an instance
attackInstance.damage = 45; //Set the damage of this _instance_ to 45
attackInstance.speed = 4; //Make it move
attackInstance.direction = point_direction(x, y, mouse_x, mouse_y); //in the right direction
在与obj_enemy obj_attack的碰撞事件中:
hp -= other.attack*2; //My HP gets down by the amount of the attack variable in the collided instance.
with(other) {
instance_destroy(); //Destroy the attack object
}
这基本上应该可以解决问题:)