Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by greatwhiteshark17283 · Feb 24, 2014 at 10:00 PM · camerascreenshotviewcapturecapturescreen

How to get a screenshot in game and re-use in game?

For my game, when you die, I want to know how to save the image that the player viewed last and then save it so then you can view it on a newspaper in the game. Basically, I want to know how to keep an image that the player saw and make it so then it can be viewed later on. Almost like those games that let you take pictures with a camera and then view them later.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jamora · Feb 24, 2014 at 10:08 PM 0
Share

I would start looking into Application.CaptureScreenshot and the WWW class. This Answer might give you ideas.

avatar image greatwhiteshark17283 · Feb 24, 2014 at 10:21 PM 0
Share

Thanks but don't think that that's what I want. What I meant is that I want everything to be in the game. I would want to somehow be able to make a texture from an image in the game and then put it into a material or something. I don't really want to save any images to the players computer from the game.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Feb 24, 2014 at 11:02 PM

You can use Texture2D.ReadPixels() to grab the screen. Here is a bit of demonstration code. To use:

  • Create a Quad

  • Scale the Quad so that the aspect ratio is approximately the same as the screen (optional)

  • Create a material that uses the Unlit/Texture shader with no texture

  • Attach the material to the Quad

  • Attach this script to the Quad

  • Run and use the space bar to get a screen capture:


       private var tex2D : Texture2D = null;
     
       function Update () {
          if (Input.GetKeyDown(KeyCode.Space)) 
             CaptureScreen();
       } 
     
       function CaptureScreen() {
         yield WaitForEndOfFrame();
         if (tex2D == null);
             tex2D = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
         tex2D.ReadPixels(Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
         tex2D.Apply();
         renderer.material.mainTexture = tex2D;
      }
    
    

Note there was a question on UA in the last month about ReadPixels not working on iOS. I don't know if this is a real issue, or some problem with the OPs code, but if you are targeting iOS, you might want to check it out. If it turns out to be a problem, Jamora's suggestion of writing out the screen shot using Application.CaptureScreenshot and reading the results back in is an alternative.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image greatwhiteshark17283 · Feb 24, 2014 at 11:12 PM 0
Share

Thanks a lot. That's exactly what I needed!

avatar image Hims · Feb 17, 2015 at 07:47 AM 0
Share

Thanks your code worked for me too!! i was looking for like this also.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I need to take (save) a screenshot from a camera other than the main one. How would I do this? 0 Answers

Specifying a camera using ScreenShotMovie and changing capture rate while not affecting playback rate 1 Answer

3rd person camera script 2 Answers

What is the typical setup for switching between third and first person, in terms of model culling? 0 Answers

increase the draw distance? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges