Hello!
I just started scripting on Defold and I ran into a problem with bullets, I can’t figure out how to make it so the gun will fire one bullet per click(even when the button is held down). I searched in the forums and documentation but I didn’t find anything that could help me.
Here is a gif of said problem:
This is the script for the mouse input
function update(self, dt)
if click == true then
msg.post(“/bulletplayer#script”,“shoot”)
click = false
end
end
function on_input(self, action_id, action)
if action_id == hash(“mouseleft”) then
if gui.pick_node(gui.get_node(“HUD2”), action.x, action.y) and action.released then
print(“node”)
elseif click == false then
click = true
print(“aaa”)
end
endend
– Add input-handling code here
– Remove this function if not needed
end
And this is the factory script:
function on_message(self, message_id, message, sender)
if message_id == hash("shoot") and debounce == false then dir = 1 if go.get_rotation("char") == vmath.vector3(0,180,0) then dir = -1 end local plrpos = go.get_position("char")
b = factory.create(“#factory”,vmath.vector3(plrpos.x,plrpos.y,-0.5), nil, {dmg = 15},vmath.vector3(4,4,40))
end
end
I hope that I gave you enough information to understand my problem, and thank you in advance!