Although collective efforts are common in both animal and human societies, many human and probably animal social dilemmas have no obvious cooperative solution, which is a challenge for evolutionary biologists. In public goods games, i.e. the experimental paradigm for studying the sustainability of a public resource with human subjects, initial cooperation usually declines quickly. Recently, it has been shown that the interaction with another social game in which good reputation attracts help, can maintain a high level of cooperation in the public goods game. Here we show experimentally that humans use different strategies in the public goods game conditional on whether the player knows that his decisions will be either known or unknown in another social game. The knowledge of being recognized as the same individual in both scenarios motivates players to invest in their reputation and thus sustain the public resource. However, cooperation declines immediately when individual identities switch from being recognizable to being unrecognizable between the two interacting games.