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 KateHassan · Jul 17, 2018 at 02:35 PM · loopfor-loopscreenshotif

taking and saving multiple screenshots into a folder in game play

I am trying to take screenshots in game play and save them all into a folder. this is my v basic code so far:

private float allowedScreenshots;

void Update () { for (int i = 0; i < allowedScreenshots; i++) { if (Input.GetMouseButtonDown(1)) ScreenCapture.CaptureScreenshot("Screenshot" + i + ".png"); }
} when i play the game it is saving the last screenshot and saving it as Screenshot9.png. I understand it is only saving the last thing and I need to be keeping them as the loop goes but I don't know c# very well and I am stuck! Also the counter is going up even when I don't click I think??

I am a complete novice, help is much appreciated!

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

1 Reply

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

Answer by Harinezumi · Jul 17, 2018 at 02:56 PM

The code that you have will take allowedScreenshots number of screenshots of the same frame and always name them as "Screenshot#.png", where # is a number less than allowedScreenshots. This happens because you are taking screenshots in the same frame, because you call it in Update().

The correct approach is to store in the class the number of the last screenshot taken, and not use a loop at all::

 public class ScreenShotter : MonoBehaviour {
 
     [SerializeField] private int maxAllowedScreenshots = 1; // set it a value in the Editor
 
     private int nextScreenshotIndex = 0;
 
     private void Update () {
         if (Input.GetmouseButtonDown(1) && nextScreenshotIndex < maxAllowedScreenshots) {
             ScreenCapture.CaptureScreenshot("Screenshot" + nextScreenshotIndex + ".png");
             nextScreenshotIndex++;
         }
     }
 
 }

Btw, a recommendation: don't use float data type for numbers that should only be integer, it is sub-optimal and confusing. As there is no such thing as a partial index or screenshot, the screenshot number related variables should be int.

Comment
Add comment · Show 5 · 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 KateHassan · Jul 17, 2018 at 03:38 PM 0
Share

thank you for your reply! however it is now only saving the first screenshot as screenshot0.png. does there not need to be a for loop in there?? I set maxAllowedScreenshots = 10

avatar image Harinezumi KateHassan · Jul 17, 2018 at 03:57 PM 0
Share

I assumed that you want to take a screen shot every time you right click until you have taken the maximum allowed number of screenshots, but probably I misunderstood something. What is it that you would like to do? Would you like to take a number of screenshots starting when you press the button? Or...?
If you use a for loop, it will take a number of screenshots of the same frame. I assumed that's not what you want, because I don't see what use it has...

avatar image KateHassan · Jul 18, 2018 at 08:07 AM 0
Share

Yes and I want to save all of them! at the moment it is only saving one screenshot and I can't figure out why

avatar image KateHassan KateHassan · Jul 18, 2018 at 08:28 AM 0
Share

never$$anonymous$$d I figured it out I changed the maxallowed screenshots in my script not in unity! silly. thanks for your help! :D

avatar image Harinezumi KateHassan · Jul 18, 2018 at 09:06 AM 0
Share

Great! If you think my answer was the solution, please accept it, so that other users might also find the answer.

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

87 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

Related Questions

using "for" in Unity Script HELP! 2 Answers

How to have a (wait) yield on a for loop? 0 Answers

How do I reset a for loop variable??? 3 Answers

How do I create a variable for each GameObject that I added to an array by using a loop? 2 Answers

for loop problem,problem with for loop 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