Created
June 29, 2015 08:05
-
-
Save peroon/4d316129f8264a5e897b to your computer and use it in GitHub Desktop.
[Unity]Take ScreenShot of GameView and assign it as material texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.IO; | |
public class Temp : MonoBehaviour { | |
void Start () { | |
StartCoroutine (this.TakeScreenShot ()); | |
} | |
IEnumerator TakeScreenShot(){ | |
// Screenshot を撮る | |
string path = Application.dataPath + "/screenshot.png"; | |
Application.CaptureScreenshot(path); | |
Debug.Log("path:"+path); | |
// 即座に保存されるわけではないので待ち | |
while(!System.IO.File.Exists(path)){ | |
print ("Saving"); | |
yield return null; | |
} | |
// スクリーンショットの読み込み | |
byte[] image = File.ReadAllBytes(path); | |
// Texture2D を作成して読み込み | |
Texture2D tex = new Texture2D(0, 0); | |
tex.LoadImage(image); | |
GameObject.Find ("Cube").GetComponent<Renderer> ().material.mainTexture = tex; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment