Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by derier44 · Feb 08, 2016 at 12:54 PM · cameratextureimagefilescreenshot

Taking a Screenshot and then displaying the Screenshot in game

Hi all!

I'm making a game that has photography mechanics and I figured the best way to do this would be to take a screenshot using Application.CaptureScreenshot and then reassigning the taken screenshot to an object as a Texture.

The problem I am running into is after I successfully take the screenshot I am unable to get the game to reload the new image onto the object during runtime. The image will successfully reload after restarting the editor or by pausing and unpausing in the editor. Also, I was able to get it to work by using the UnityEditor.AssetDatabase.Refresh and then telling Unity to assign the screenshot as a texture. While this last method works in the editor, it won't work in a build which is what I need.

Is there a way I can tell Unity every once in a while to refresh a folder so that way it will apply the changes that have been made in game?

Here is my code:

Screenshot.cs attatched to the Player

 using UnityEngine;
 using System.Collections;
 using System.IO;
 
 public class ScreenShot : MonoBehaviour {
 
     public GameObject ui_CameraUI;
     private bool startResetCameraUI;
     private float resetCameraUI;
 
     void Start(){
         resetCameraUI = 0.0f;
     }
 
     void Update(){
         if (Input.GetButtonDown ("Fire1")) {
             ui_CameraUI.SetActive (false);
         }
     }
 
     void LateUpdate() {
         if (startResetCameraUI) {
             resetCameraUI += Time.deltaTime;
         }
 
         if (resetCameraUI >= 0.000001f) {
             ui_CameraUI.SetActive (true);
             startResetCameraUI = false;
             resetCameraUI = 0.0f;
         }
         
         if(Input.GetButtonDown("Fire1")){
             if (Application.isEditor) {
                 Application.CaptureScreenshot ("Assets\\Resources\\Screenshot.bytes");
             } else {
                 Application.CaptureScreenshot ("Resources\\Screenshot.bytes");
             }
             Debug.Log ("*Camera Sound*");
             startResetCameraUI = true;
         }
     }
 }
 

TextureReassign.cs attatched to a GameObject

 using UnityEngine;
 using System.Collections;
 
 public class MaterialReassign : MonoBehaviour {
 
     void Update(){
         Texture newpic = Resources.Load("Screenshot", typeof(Texture)) as Texture; 
         gameObject.GetComponent<Renderer> ().material.mainTexture = newpic; 
     }
 }


Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Get a JPG/ PNG Render from a Selected Camera ? 0 Answers

I can not see the title screen of my game 0 Answers

How to match position with Mini Map UI 0 Answers

Need help with an image path script 0 Answers

Why is there difference between android device resolution and webcamtexture resolution 0 Answers


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