function CreateEntity( prefab, name, counterName, zValue )
	local counter = OWNER:GetInt( counterName )
	GAME:GetGameState():GetEntityFactory():CreateEntity( prefab, name .. counter, GetPositionForNewObject( zValue ) )
	GAME:GetGameState():GetEntityManager():GetEntity( name .. counter ):Enable()
	OWNER:SetString( "selectedEntity", name .. counter )
	OWNER:SetInt( counterName, counter + 1 )
	
	GAME:GetGameState():GetEntityManager():GetEntity( "Selection" ):Enable()
	GAME:GetGameState():GetEntityManager():GetEntity( "Selection" ):GetNode():SetScale( game.Vector( 1, 1 ) )
	GAME:GetGameState():GetEntityManager():GetEntity( "Selection" ):GetNode2D():SetAngle( game.Radian( 0 ) )
	
end

function CreateRotator()
	local zValue = 0.5
	if OWNER:GetString( "lastAction" ) ~= "newRotator" then
		OWNER:SetString( "lastAction", "newRotator" )
		CreateEntity( "Rotator", "Rotator", "numRotators", zValue )
		print( "newRotator" )
	end
end

function CreateWall()
	local zValue = 0.4
	if OWNER:GetString( "lastAction" ) ~= "newWall" then
		OWNER:SetString( "lastAction", "newWall" )
		CreateEntity( "Wall", "Wall", "numWalls", zValue )
		print( "newWall" )
	end
end

function CreateDeathZone()
	local zValue = 0.7
	if OWNER:GetString( "lastAction" ) ~= "newDeathZone" then
		OWNER:SetString( "lastAction", "newDeathZone" )
		CreateEntity( "DeathZone", "DeathZone", "numDeathZones", zValue )
		print( "newDeathZone" )
	end
end

function CreateGoal()
	local zValue = 0.6
	if OWNER:GetString( "lastAction" ) ~= "newGoal" then
		OWNER:SetString( "lastAction", "newGoal" )
		CreateEntity( "Goal", "Goal", "numGoals", zValue )
		print( "newDeathZone" )
	end
end

function CreateCheckpoint()
	local zValue = 0.55
	if OWNER:GetString( "lastAction" ) ~= "newCheckpoint" then
		OWNER:SetString( "lastAction", "newCheckpoint" )
		CreateEntity( "Checkpoint", "Checkpoint", "numCheckpoints", zValue )
		print( "newCheckpoint" )
	end
end

function GetPositionForNewObject( zValue )
	local cursor = GAME:GetGameState():GetEntityManager():GetEntity( "cursor" )
	local cursorPos = game.Vector( cursor:GetFloat( "posx" ), cursor:GetFloat( "posy" ) )
	local posData = game.NodeData()
	posData:SetPosition( game.Vector( cursorPos.m_x, cursorPos.m_y, zValue ) )
	return posData
end