- Home /
Question by
XDeltas · May 14, 2014 at 05:51 AM ·
c#playerprefsscreenshot
Errors and suggestions
getting 2 errors: Assets/Scripts/TakeScreenshot.cs(23,39): error CS1525: Unexpected symbol private' Assets/Scripts/TakeScreenshot.cs(13,17): error CS1525: Unexpected symbol
}' Also any suggestion to improve
using UnityEngine;
using System.Collections;
public class TakeScreenshot : MonoBehaviour
{
public string captureKey = "f2";
void Start (){
if (PlayerPrefs.HasKey("ScreenshotNumber") == false)
{
PlayerPrefs.SetInt("ScreenshotNumber", 1)
}
}
void Update()
{
private int screenshotCount = PlayerPrefs.GetInt("ScreenshotNumber")
if (Input.GetKeyDown(captureKey))
{
string screenshotFilename;
do
{
private int ssn = 0
ssn = PlayerPrefs.GetInt("ScreenshotNumber") + 1
PlayerPrefs.SetInt("ScreenshotNumber", ssn)
screenshotFilename = "screenshot" + screenshotCount + ".png";
} while (System.IO.File.Exists(screenshotFilename));
Application.CaptureScreenshot(screenshotFilename);
}
}
}
Comment
Best Answer
Answer by robertbu · May 14, 2014 at 06:15 AM
First, the 'private' keyword is used for instance variables...the ones you declare at the top of the file that are outside of any function. It is an error to use 'private' inside a function, so remove 'private' from lines 17 and 23.
Next you are missing many ';'. You need them at the end of lines: 12, 17, 23, 24, and 25...and there may be more.
Answer by Asteiros · May 14, 2014 at 06:21 AM
do not use private inside of the method:
private int screenshotCount = PlayerPrefs.GetInt("ScreenshotNumber")
int screenshotCount = PlayerPrefs.GetInt("ScreenshotNumber");