1
2
3
4
5
6
7
|
public
void
IStart() { SceneManager.LoadScene( "Scene1" ); } public
void
IExit() { Application.Quit(); } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
using
UnityEngine; using
System.Collections; public
class
followTarget : MonoBehaviour { public
float
smoothing = 3; private
Transform player; //
Use this for initialization void
Start() { //player
= GameObject.FindGameObjectWithTag(Tags.player).transform; player
= GameObject.Find( "swimmer" ).transform; } //
Update is called once per frame void
FixedUpdate() { Vector3
targetPos = player.position + new
Vector3(0, 0, -6); transform.position
= Vector3.Lerp(transform.position, targetPos, smoothing * Time.deltaTime); } } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
using
UnityEngine; using
System.Collections; using
UnityEngine.UI; using
UnityEngine.SceneManagement; public
class
Move : MonoBehaviour { public
float
speed = 1; float
speed1 = 0; float
i = 0; int
m = 0; //時間 int
n = 0; //點擊次數 Vector2
ToPos = new
Vector2(1,1); GameObject
player; Text
indexClick; Text
indexTime; bool
ifSave = true ; //動畫組件 private
Animator mAnim; //
Use this for initialization void
Start () { player
= GameObject.Find( "swimmer" ); indexClick
= GameObject.Find( "Canvas" ).transform.Find( "clickText" ).GetComponent<Text>(); indexTime
= GameObject.Find( "Canvas" ).transform.Find( "timeText" ).GetComponent<Text>(); mAnim
= GetComponent<Animator>(); mAnim.SetBool( "idle" ,
true ); mAnim.SetBool( "swim" ,
false ); } //
Update is called once per frame void
Update () { if
(Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.X)) { speed1
+= 0.9f; n++; indexClick.text
= "點
擊 次 數:"
+ n.ToString(); mAnim.SetBool( "swim" ,
true ); mAnim.SetBool( "restart" ,
true ); } else
if (speed1
> 0) { speed1
-= 0.09f; mAnim.SetBool( "swim" ,
false ); mAnim.SetBool( "restart" ,
false ); } else { speed1
= 0; mAnim.SetBool( "stop" ,
true ); } GetComponent<Rigidbody2D>().MovePosition(transform.position
+ new
Vector3(1, 0, 1) * speed1 * Time.deltaTime); //秒計時器 if
(i >= 1.0f) { i
= 0; m++; indexTime.text
= "用時(秒):"
+ m.ToString(); //print(m); } i
+= Time.deltaTime; //數據存儲 if
(player.transform.position.x > 8.4f && ifSave == true ) { PlayerPrefs.SetInt( "indexClick" ,
n); PlayerPrefs.SetInt( "indexTime" ,
m); ifSave
= false ; SceneManager.LoadScene( "Scene2" ); } } } |
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
using
UnityEngine; using
System.Collections; using
UnityEngine.UI; using
UnityEngine.SceneManagement; public
class
showFinal : MonoBehaviour { int
indexTime; int
indexClick; Text
ClickText; Text
TimeText; //
Use this for initialization void
Start () { indexClick
= PlayerPrefs.GetInt( "indexClick" ); indexTime
= PlayerPrefs.GetInt( "indexTime" ); ClickText
= GameObject.Find( "Canvas" ).transform.Find( "clickText" ).GetComponent<Text>(); TimeText
= GameObject.Find( "Canvas" ).transform.Find( "timeText" ).GetComponent<Text>(); ClickText.text
= "點
擊 次 數:"
+ indexClick.ToString(); TimeText.text
= "用時(秒):"
+ indexTime.ToString(); } //
Update is called once per frame void
Update () { } public
void
Restart() { SceneManager.LoadScene( "Scene1" );
} public
void
Exit() { Application.Quit(); } } |