Application.Capturescreenshot?

polycounter lvl 4
Offline / Send Message
hmm_rock polycounter lvl 4
I'm trying to take some high res screenshots of a level in unity using Application.Capturescreenshot, but I'm having trouble with it. I can't seem to get it to work. I've tried creating the script and attaching it to an empty game object, I've tried attaching it to the camera.

Does anyone have experience with this or can anyone suggest an easier way to get some screenshots?

Replies

  • Farfarer
    Offline / Send Message
    Farfarer Polycount Sponsor
    I have two files...

    Editor/ScreenshotEditor.js
    #pragma strict
    
    @CustomEditor (Screenshot)
    class ScreenshotEditor extends Editor {
    
    	var fileName : String = "Screenshot";
    	var scale : int = 2;
    
    	function OnInspectorGUI () {
    		scale = EditorGUILayout.IntField ( scale );
    		fileName = EditorGUILayout.TextField ( fileName );
    		if ( GUILayout.Button ( "Take Screenshot" ) ) {
    			(target as Screenshot).TakeScreenshot ( fileName, scale );
    		}
    	}
    }
    

    and

    Screenshot.js
    #pragma strict
    
    function TakeScreenshot ( filename : String, scale : int ) {
    	Application.CaptureScreenshot ( filename + ".png", scale );
    }
    

    That should give you a Screenshot component you can add to whatever you like, I've attached it to my camera. Then it should have a custom editor with a "Take Screenshot" button and fields for the filename and a scale multiplier (means you can take screenshots that are larger than the current viewport).
  • hmm_rock
    Offline / Send Message
    hmm_rock polycounter lvl 4
    Hey thanks for taking the time to share this. This is a stupid question, but could you explain the process of implementing this script? I have very minimal knowledge of scripting (though I'm trying to learn) and I must be doing something all together wrong. Do I need to change something unique in the script?

    My process right now is simply to create a new javascript, paste this script, save it, add component/script to my camera. The script file appears, but nothing else. I'm sorry if I'm making a really dumb mistake, but I appreciate any help in sorting this out
  • Farfarer
    Offline / Send Message
    Farfarer Polycount Sponsor
    Put the editor script inside a folder called Editor somewhere in your assets folder, call it ScreenshotEditor.js.

    Put the second bit of code into a file called Screenshot.js and apply it as a component to something. You should see it appear with buttons and fields.
  • hmm_rock
    Offline / Send Message
    hmm_rock polycounter lvl 4
Sign In or Register to comment.