Building game rewrites web.html page

I wanted to make my game open url page but in separate tab instead of the same window as my web build, so I made a function that does that by using Application.ExternalCall () function in unity.

Though the code works and the page is oppened in new tab, when I build my game, web.html page is rewriten from scratch using some default code template, i.e my code disappears.

Is there a way how to prevent this from happening or is there a place where I can edit what is generated by default in the web.html page?

I’ve not done this for web games, but I would have thought you could make a PostProcess script that would open the html file and replace the contents.

Examples: Unity - Scripting API: PostProcessBuildAttribute
Note it’s the [PostProcessBuild(x)] attribute that actually tells this to run once the build has completed. x should be replaced by the order you want this to run (so something where x=1 will run before something with x=200)

Here’s a pretty together sample (sorry for errors if there are any, it’s off the top of my head)

public static class cChangeSomething {

	[PostProcessBuild(200)]
	public static void OnPostProcessBuild(BuildTarget target, string path)
	{
			ChangeSomething (path);
	}


	public static void ChangeSomething(string path)
	{
		string fullPath = Path.Combine(path, Path.Combine(Path.Combine("Folder1", "Folder2"), "myfile.html"));
		string data = Load (fullPath);

		string wholeStatement = "This is the text you want to insert";
		data = Regex.Replace (data, @"This is the text you want to replace", wholeStatement);
		
		Save (fullPath, data);

	}
}

You can define a web page to serve as a template for your web build in future.
Here is the page where I found this info: http://docs.unity3d.com/Manual/UsingWebPlayertemplates.html

Create a folder called WebPlayerTemplates in your assets folder and then create another folder which will hold all files about the specific template. You can have multiple web templates and once you restart your Unity and reload your project, the templates will appear in Build Settings → Player Settings → Web Player.

The template must have index.html page and you can create thumbnail.png, 128x128 to serve as image in the templates section in Unity.

Was about to delete the question but it is useful so… :slight_smile: