1

我目前正在gamemaker中制作游戏。玩家攻击的工作原理是让玩家获得耐力并将其存储在一个伤害变量中,然后飞出玩家并击中敌人,从敌人身上获得两倍于伤害变量的生命值。

如果玩家在进行攻击时有 45 的耐力,则攻击精灵会飞出并造成 45 的伤害。当击中敌人时,这将对敌人造成 90 点伤害,只剩下 10 点生命值。

问题是游戏似乎不知道哪个攻击精灵击中了敌人,因为您可以执行基本上无限量的攻击,因此不会对敌人施加正确的伤害量。

我如何获得与敌人碰撞的对象的实例 ID,以便我可以使用它来访问损坏变量?

提前致谢

4

2 回答 2

1

我假设您正在使用与敌人的碰撞事件,对吗?在其中,您应该能够使用other. 所以,像这样:

var instance_id = other.id

以下是来自 YoYoGames 的更多信息:

https://docs.yoyogames.com/source/dadiospice/002_reference/001_gml%20language%20overview/keywords.html

这是名单上的第二个:)

于 2017-02-08T16:24:38.483 回答
1

这是 Jeremy ment 的代码示例:

触发攻击的事件(例如全局鼠标留在玩家对象中):

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
}

这基本上应该可以解决问题:)

于 2017-02-20T10:20:55.283 回答