奥运测手速小游戏(傅女神)

看到傅园慧女神的洪荒之力,心中也充满了洪荒之力,顺势做一个测手速的小游戏,虽然做的有点渣。谁让我既不会美术又不会动画,图还得自己做、动画还得自己截,差点折腾死我。
下面展示(轻吐槽,我知道做得难看):
再说一下:资源、图、动画啥的就不要太认真了,我费了九牛二虎之力也只这个水平了。(PS:大部分时间就和这些杠上了,没美工真可怕)

首先,第一个scene一张图说明下一下:
 
这个scene的脚本我都不想贴,就这两东西
[C#]  纯文本查看  复制代码
?
 
1
2
3
4
5
6
7
public void IStart()
     {
         SceneManager.LoadScene( "Scene1" );
     }
     public void IExit()
     {
         Application.Quit();
     }


第二个scene也先来一张图,清晰明了:
这部分使用了两块代码,分别是相机平滑跟随player的followTarget.cs和Move.cs。
其中的第二个脚本虽然用最通俗的if来写的,但是包含了移动的加速减速、动画的播放停止、秒计时器、数据存储等诸多方面,列出来看看吧。
[C#]  纯文本查看  复制代码
?
 
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);
     }
}


[C#]  纯文本查看  复制代码
?
 
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" );
         }
         
         }
}


第三部分就更简单了,取一下第二个scene存的数据,然后显示出来就行了。本来想加个排行榜,然后想了下,这个再说吧,先不浪费时间了。
如图:
代码也很简洁:
[C#]  纯文本查看  复制代码
?
 
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();
     }
}

可以发布成安卓的,也可以发布成pc的,pc的按X键或者鼠标加速,小伙伴们,爆发你的洪荒之力吧(傅女神借我点洪荒之力呗)。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值