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 /
avatar image
0
Question by Han-Wen · Jul 10, 2019 at 01:18 PM · errorcolorscreenshot

SreenShot, Color become a mess

Hello guys, I am a new in unity. I hope this question is not too silly for you. I want to make a screenshot just before I set the "TimeScale" to 0. So I choosed to use "Texture2D.ReadPixels" and "Texture2D.Apply" to returned and saved the "Texture2D". And then I used "GUI.DrawTexture" to draw the thing I had just saved. The code is work. No compile error at all. But here comes the problem. the color of the thing I had drew becomes a mess. The link at the bootom will show how terrifying it is. I googled as many as I could, but it still confuse me. Please Help!

https://drive.google.com/file/d/1N4Cgv4AOFGuiMCTwqw5abl2Y_XWT2SEL/view?usp=sharing

Comment
Add comment · Show 1
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 Bunny83 · Jul 10, 2019 at 10:19 PM 0
Share

There are countless things that could be wrong in your code. First of all you can not call ReadPixels whenever you want. If you read from screen you should do that either in OnPostRender or in a coroutine after WaitForEndOfFrame.. Next you said you use GUI.DrawTexture. This can only be used in OnGUI. It's not clear how you setup your Texture2D. Does it have the right size? What texture format do you use?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Han-Wen · Jul 11, 2019 at 01:20 AM

@Bunny83 Sorry, I didn't express clearly enough, here are my code. which script is attached to my camera.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Screenshot : MonoBehaviour
 {
     GameObject Ray;
     Rect rect;
     bool shot = false;
     Texture2D _image_tem;
 
     private void Start()
     {
         rect = new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.8f, Screen.height * 0.8f);
         Ray = GameObject.FindGameObjectWithTag("Player");
     }
 
     private void Update()
     {
         if (Input.GetKeyDown(KeyCode.J) && Character_CheckObject.isGameStop)
         {
             shot = false;
         }
     }
 
     private void OnPostRender()
     {
         if (Ray.GetComponent<Character_CheckObject>().GetShot())
         {
             _image_tem = CaptureScreenshot(rect);
             shot = true;
             Ray.GetComponent<Character_CheckObject>().SetShot_False();
         }        
     }
 
     private void OnGUI()
     {
         if (shot)
         {
             GUI.DrawTexture(new Rect(10, 10, 400, 300), _image_tem);
             Debug.Log(123);
         }        
     }
 
     public Texture2D CaptureScreenshot(Rect rect)
     {
         Texture2D screenshot = new Texture2D((int)rect.width,(int)rect.height,TextureFormat.RGB24,false);
         screenshot.ReadPixels(rect, 0, 0);
         screenshot.Apply();
         return screenshot;
     }
 }
 
Comment
Add comment · 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

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

141 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 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 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 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 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 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 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

Object Reference Error On Camera Script 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Capture Screenshot not working in WebGL 1 Answer

Changing two different objects renderer colour 1 Answer

the problem of touch screen logic 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