trò chơi game bóng rổ full code
31.739 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4 public class FocusCamera : MonoBehaviour {
5 public Camera SSCamera;
6 private GameObject SSPanel;
7 private Texture2D screenShot;
8 private bool displaySS=false;
9 private int imWidth = 240;
10 private int imHeight = 180;
11
12 void OnTriggerEnter() //if ball hits basket collider
13 {
14 int scWidth = Screen.width;
15 //int scHeigth = Screen.height;
16 if (scWidth > 800) {
17 imWidth = 320;
18 imHeight = 240;
19 }
20 else if (scWidth > 1200) {
21 imWidth = 400;
22 imHeight = 300;
23 }
24 RenderTexture rt = new RenderTexture(imWidth,imHeight,24);
25 SSCamera.targetTexture = rt;
26 screenShot = new Texture2D(imWidth,imHeight,TextureFormat.RGB24, false);
27 SSCamera.Render ();
28 RenderTexture.active = rt;
29 screenShot.ReadPixels(new Rect(0,0, imWidth,imHeight), 0, 0);
30 SSCamera.targetTexture=null;
31 RenderTexture.active=null;
32 Destroy(rt);
33
34 byte[] bytes = screenShot.EncodeToPNG();
35 screenShot.LoadImage (bytes);
36
37 StartCoroutine (ShowSS ());
38
39 }
40
41 IEnumerator ShowSS() {
42 // Fancy pants flash of label on and off
43 displaySS = true;
44 yield return new WaitForSeconds(3);
45 displaySS = false;
46 }
47
48 void OnGUI() {
49 if (displaySS == true) {
50 int scWidth = Screen.width;
51 int scHeigth = Screen.height;
52 if (scWidth > 400)
53 GUI.Label (new Rect (scWidth/2.75f, scHeigth/3, scWidth/2.5f, scHeigth/2.5f), screenShot);
54 else if (scWidth > 800)
55 GUI.Label (new Rect (scWidth/3, scHeigth/3, scWidth/1.5f, scHeigth/1.5f), screenShot);
56 else if (scWidth > 1200)
57 GUI.Label (new Rect (scWidth/3.5f, scHeigth/3, scWidth/2.5f, scHeigth/2.5f), screenShot);
58 }
59 }
60
61 }
2 using System.Collections;
3
4 public class FocusCamera : MonoBehaviour {
5 public Camera SSCamera;
6 private GameObject SSPanel;
7 private Texture2D screenShot;
8 private bool displaySS=false;
9 private int imWidth = 240;
10 private int imHeight = 180;
11
12 void OnTriggerEnter() //if ball hits basket collider
13 {
14 int scWidth = Screen.width;
15 //int scHeigth = Screen.height;
16 if (scWidth > 800) {
17 imWidth = 320;
18 imHeight = 240;
19 }
20 else if (scWidth > 1200) {
21 imWidth = 400;
22 imHeight = 300;
23 }
24 RenderTexture rt = new RenderTexture(imWidth,imHeight,24);
25 SSCamera.targetTexture = rt;
26 screenShot = new Texture2D(imWidth,imHeight,TextureFormat.RGB24, false);
27 SSCamera.Render ();
28 RenderTexture.active = rt;
29 screenShot.ReadPixels(new Rect(0,0, imWidth,imHeight), 0, 0);
30 SSCamera.targetTexture=null;
31 RenderTexture.active=null;
32 Destroy(rt);
33
34 byte[] bytes = screenShot.EncodeToPNG();
35 screenShot.LoadImage (bytes);
36
37 StartCoroutine (ShowSS ());
38
39 }
40
41 IEnumerator ShowSS() {
42 // Fancy pants flash of label on and off
43 displaySS = true;
44 yield return new WaitForSeconds(3);
45 displaySS = false;
46 }
47
48 void OnGUI() {
49 if (displaySS == true) {
50 int scWidth = Screen.width;
51 int scHeigth = Screen.height;
52 if (scWidth > 400)
53 GUI.Label (new Rect (scWidth/2.75f, scHeigth/3, scWidth/2.5f, scHeigth/2.5f), screenShot);
54 else if (scWidth > 800)
55 GUI.Label (new Rect (scWidth/3, scHeigth/3, scWidth/1.5f, scHeigth/1.5f), screenShot);
56 else if (scWidth > 1200)
57 GUI.Label (new Rect (scWidth/3.5f, scHeigth/3, scWidth/2.5f, scHeigth/2.5f), screenShot);
58 }
59 }
60
61 }
void OnTriggerEnter() if ball hits basket collider
int scHeigth = Screen.height;
Fancy pants flash of label on and off