这是 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
}
这基本上应该可以解决问题:)