Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Unity让梦想成为现实
FlappyBird2021
提交
995c6986
F
FlappyBird2021
项目概览
Unity让梦想成为现实
/
FlappyBird2021
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
FlappyBird2021
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
995c6986
编写于
9月 07, 2021
作者:
Unity让梦想成为现实
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
实现了小鸟的抬头低头效果,碰撞检测
上级
d4882963
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
322 addition
and
18 deletion
+322
-18
Assets/Resources/Prefab/Pip.prefab
Assets/Resources/Prefab/Pip.prefab
+112
-0
Assets/Scenes/SampleScene.unity
Assets/Scenes/SampleScene.unity
+129
-3
Assets/Scripts/Bird.cs
Assets/Scripts/Bird.cs
+35
-11
Assets/Scripts/GameController.cs
Assets/Scripts/GameController.cs
+46
-4
未找到文件。
Assets/Resources/Prefab/Pip.prefab
浏览文件 @
995c6986
%YAML
1.1
%YAML
1.1
%TAG
!u!
tag:unity3d.com,2011:
%TAG
!u!
tag:unity3d.com,2011:
---
!u!1
&6243242003816384578
GameObject
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
serializedVersion
:
6
m_Component
:
-
component
:
{
fileID
:
5667231155455462974
}
-
component
:
{
fileID
:
7174408626539812788
}
m_Layer
:
0
m_Name
:
Score
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
m_NavMeshLayer
:
0
m_StaticEditorFlags
:
0
m_IsActive
:
1
---
!u!4
&5667231155455462974
Transform
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
6243242003816384578
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0.34
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
6470098503324179898
}
m_RootOrder
:
2
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
---
!u!61
&7174408626539812788
BoxCollider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
6243242003816384578
}
m_Enabled
:
1
m_Density
:
1
m_Material
:
{
fileID
:
0
}
m_IsTrigger
:
1
m_UsedByEffector
:
0
m_UsedByComposite
:
0
m_Offset
:
{
x
:
0.09667066
,
y
:
-0.00000047683716
}
m_SpriteTilingProperty
:
border
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
0
}
pivot
:
{
x
:
0
,
y
:
0
}
oldSize
:
{
x
:
0
,
y
:
0
}
newSize
:
{
x
:
0
,
y
:
0
}
adaptiveTilingThreshold
:
0
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
serializedVersion
:
2
m_Size
:
{
x
:
0.27936375
,
y
:
1.4221201
}
m_EdgeRadius
:
0
---
!u!1
&6470098503324179893
---
!u!1
&6470098503324179893
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
@@ -29,6 +86,7 @@ Transform:
...
@@ -29,6 +86,7 @@ Transform:
m_Children
:
m_Children
:
-
{
fileID
:
6470098504182819943
}
-
{
fileID
:
6470098504182819943
}
-
{
fileID
:
6470098505145496451
}
-
{
fileID
:
6470098505145496451
}
-
{
fileID
:
5667231155455462974
}
m_Father
:
{
fileID
:
0
}
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
0
m_RootOrder
:
0
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
...
@@ -42,6 +100,7 @@ GameObject:
...
@@ -42,6 +100,7 @@ GameObject:
m_Component
:
m_Component
:
-
component
:
{
fileID
:
6470098504182819943
}
-
component
:
{
fileID
:
6470098504182819943
}
-
component
:
{
fileID
:
6470098504182819940
}
-
component
:
{
fileID
:
6470098504182819940
}
-
component
:
{
fileID
:
7394891180029338623
}
m_Layer
:
0
m_Layer
:
0
m_Name
:
pipeTop
m_Name
:
pipeTop
m_TagString
:
Untagged
m_TagString
:
Untagged
...
@@ -113,6 +172,32 @@ SpriteRenderer:
...
@@ -113,6 +172,32 @@ SpriteRenderer:
m_WasSpriteAssigned
:
1
m_WasSpriteAssigned
:
1
m_MaskInteraction
:
0
m_MaskInteraction
:
0
m_SpriteSortPoint
:
0
m_SpriteSortPoint
:
0
---
!u!61
&7394891180029338623
BoxCollider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
6470098504182819942
}
m_Enabled
:
1
m_Density
:
1
m_Material
:
{
fileID
:
0
}
m_IsTrigger
:
1
m_UsedByEffector
:
0
m_UsedByComposite
:
0
m_Offset
:
{
x
:
0
,
y
:
0
}
m_SpriteTilingProperty
:
border
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
0
}
pivot
:
{
x
:
0.5
,
y
:
0.5
}
oldSize
:
{
x
:
0.7
,
y
:
4.53
}
newSize
:
{
x
:
0.7
,
y
:
4.53
}
adaptiveTilingThreshold
:
0.5
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
serializedVersion
:
2
m_Size
:
{
x
:
0.7
,
y
:
4.53
}
m_EdgeRadius
:
0
---
!u!1
&6470098505145496450
---
!u!1
&6470098505145496450
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
@@ -123,6 +208,7 @@ GameObject:
...
@@ -123,6 +208,7 @@ GameObject:
m_Component
:
m_Component
:
-
component
:
{
fileID
:
6470098505145496451
}
-
component
:
{
fileID
:
6470098505145496451
}
-
component
:
{
fileID
:
6470098505145496448
}
-
component
:
{
fileID
:
6470098505145496448
}
-
component
:
{
fileID
:
7585981152488610433
}
m_Layer
:
0
m_Layer
:
0
m_Name
:
pipeBottom
m_Name
:
pipeBottom
m_TagString
:
Untagged
m_TagString
:
Untagged
...
@@ -194,3 +280,29 @@ SpriteRenderer:
...
@@ -194,3 +280,29 @@ SpriteRenderer:
m_WasSpriteAssigned
:
1
m_WasSpriteAssigned
:
1
m_MaskInteraction
:
0
m_MaskInteraction
:
0
m_SpriteSortPoint
:
0
m_SpriteSortPoint
:
0
---
!u!61
&7585981152488610433
BoxCollider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
6470098505145496450
}
m_Enabled
:
1
m_Density
:
1
m_Material
:
{
fileID
:
0
}
m_IsTrigger
:
1
m_UsedByEffector
:
0
m_UsedByComposite
:
0
m_Offset
:
{
x
:
0
,
y
:
0
}
m_SpriteTilingProperty
:
border
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
0
}
pivot
:
{
x
:
0.5
,
y
:
0.5
}
oldSize
:
{
x
:
0.7
,
y
:
4.53
}
newSize
:
{
x
:
0.7
,
y
:
4.53
}
adaptiveTilingThreshold
:
0.5
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
serializedVersion
:
2
m_Size
:
{
x
:
0.7
,
y
:
4.53
}
m_EdgeRadius
:
0
Assets/Scenes/SampleScene.unity
浏览文件 @
995c6986
...
@@ -188,6 +188,16 @@ PrefabInstance:
...
@@ -188,6 +188,16 @@ PrefabInstance:
propertyPath
:
m_LocalEulerAnglesHint.z
propertyPath
:
m_LocalEulerAnglesHint.z
value
:
0
value
:
0
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6470098504182819942
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
propertyPath
:
m_Name
value
:
PipeTop
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6470098505145496450
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
propertyPath
:
m_Name
value
:
PipeBottom
objectReference
:
{
fileID
:
0
}
m_RemovedComponents
:
[]
m_RemovedComponents
:
[]
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
---
!u!4
&91773835
stripped
---
!u!4
&91773835
stripped
...
@@ -706,8 +716,75 @@ PrefabInstance:
...
@@ -706,8 +716,75 @@ PrefabInstance:
propertyPath
:
m_LocalEulerAnglesHint.z
propertyPath
:
m_LocalEulerAnglesHint.z
value
:
0
value
:
0
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6470098504182819942
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
propertyPath
:
m_Name
value
:
PipeTop
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6470098505145496450
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
propertyPath
:
m_Name
value
:
PipeBottom
objectReference
:
{
fileID
:
0
}
m_RemovedComponents
:
[]
m_RemovedComponents
:
[]
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
---
!u!1
&520998070
GameObject
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
serializedVersion
:
6
m_Component
:
-
component
:
{
fileID
:
520998072
}
-
component
:
{
fileID
:
520998071
}
m_Layer
:
0
m_Name
:
GroundCollider
m_TagString
:
Untagged
m_Icon
:
{
fileID
:
0
}
m_NavMeshLayer
:
0
m_StaticEditorFlags
:
0
m_IsActive
:
1
---
!u!61
&520998071
BoxCollider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
520998070
}
m_Enabled
:
1
m_Density
:
1
m_Material
:
{
fileID
:
0
}
m_IsTrigger
:
1
m_UsedByEffector
:
0
m_UsedByComposite
:
0
m_Offset
:
{
x
:
0.017357469
,
y
:
-0.47608316
}
m_SpriteTilingProperty
:
border
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
0
}
pivot
:
{
x
:
0
,
y
:
0
}
oldSize
:
{
x
:
0
,
y
:
0
}
newSize
:
{
x
:
0
,
y
:
0
}
adaptiveTilingThreshold
:
0
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
serializedVersion
:
2
m_Size
:
{
x
:
5.2130203
,
y
:
2.2132251
}
m_EdgeRadius
:
0
---
!u!4
&520998072
Transform
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
520998070
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0
,
y
:
-3.07
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
0
}
m_RootOrder
:
6
m_LocalEulerAnglesHint
:
{
x
:
0
,
y
:
0
,
z
:
0
}
---
!u!4
&641561914
stripped
---
!u!4
&641561914
stripped
Transform
:
Transform
:
m_CorrespondingSourceObject
:
{
fileID
:
6470098503324179898
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
m_CorrespondingSourceObject
:
{
fileID
:
6470098503324179898
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
...
@@ -781,6 +858,16 @@ PrefabInstance:
...
@@ -781,6 +858,16 @@ PrefabInstance:
propertyPath
:
m_LocalEulerAnglesHint.z
propertyPath
:
m_LocalEulerAnglesHint.z
value
:
0
value
:
0
objectReference
:
{
fileID
:
0
}
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6470098504182819942
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
propertyPath
:
m_Name
value
:
PipeTop
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
6470098505145496450
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
propertyPath
:
m_Name
value
:
PipeBottom
objectReference
:
{
fileID
:
0
}
m_RemovedComponents
:
[]
m_RemovedComponents
:
[]
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
f8f796c45dbd38a47aa327783411195c
,
type
:
3
}
---
!u!1
&851467229
---
!u!1
&851467229
...
@@ -796,6 +883,7 @@ GameObject:
...
@@ -796,6 +883,7 @@ GameObject:
-
component
:
{
fileID
:
851467230
}
-
component
:
{
fileID
:
851467230
}
-
component
:
{
fileID
:
851467233
}
-
component
:
{
fileID
:
851467233
}
-
component
:
{
fileID
:
851467234
}
-
component
:
{
fileID
:
851467234
}
-
component
:
{
fileID
:
851467235
}
m_Layer
:
0
m_Layer
:
0
m_Name
:
Bird
m_Name
:
Bird
m_TagString
:
Untagged
m_TagString
:
Untagged
...
@@ -860,7 +948,7 @@ SpriteRenderer:
...
@@ -860,7 +948,7 @@ SpriteRenderer:
m_LightmapParameters
:
{
fileID
:
0
}
m_LightmapParameters
:
{
fileID
:
0
}
m_SortingLayerID
:
174451655
m_SortingLayerID
:
174451655
m_SortingLayer
:
2
m_SortingLayer
:
2
m_SortingOrder
:
0
m_SortingOrder
:
1
m_Sprite
:
{
fileID
:
-6583155732020471796
,
guid
:
5d16aab893e4b54409e4e28c1b4735d2
,
m_Sprite
:
{
fileID
:
-6583155732020471796
,
guid
:
5d16aab893e4b54409e4e28c1b4735d2
,
type
:
3
}
type
:
3
}
m_Color
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
m_Color
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
...
@@ -901,8 +989,9 @@ MonoBehaviour:
...
@@ -901,8 +989,9 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
floatScall
:
0.3
floatScall
:
0.3
floatRate
:
1
floatRate
:
1
gravityScall
:
2.3
downSpeed
:
-6
force
:
330
jumpSpeed
:
6
reduceSpeed
:
20
---
!u!50
&851467234
---
!u!50
&851467234
Rigidbody2D
:
Rigidbody2D
:
serializedVersion
:
4
serializedVersion
:
4
...
@@ -924,6 +1013,43 @@ Rigidbody2D:
...
@@ -924,6 +1013,43 @@ Rigidbody2D:
m_SleepingMode
:
1
m_SleepingMode
:
1
m_CollisionDetection
:
0
m_CollisionDetection
:
0
m_Constraints
:
0
m_Constraints
:
0
---
!u!60
&851467235
PolygonCollider2D
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
851467229
}
m_Enabled
:
1
m_Density
:
1
m_Material
:
{
fileID
:
0
}
m_IsTrigger
:
1
m_UsedByEffector
:
0
m_UsedByComposite
:
0
m_Offset
:
{
x
:
0
,
y
:
0
}
m_SpriteTilingProperty
:
border
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
0
}
pivot
:
{
x
:
0.5
,
y
:
0.5
}
oldSize
:
{
x
:
0.8
,
y
:
0.6
}
newSize
:
{
x
:
0.8
,
y
:
0.6
}
adaptiveTilingThreshold
:
0.5
drawMode
:
0
adaptiveTiling
:
0
m_AutoTiling
:
0
m_Points
:
m_Paths
:
-
-
{
x
:
0.08030242
,
y
:
0.15283234
}
-
{
x
:
-0.036418624
,
y
:
0.15283242
}
-
{
x
:
-0.06597688
,
y
:
0.13745669
}
-
{
x
:
-0.09509341
,
y
:
0.12150282
}
-
{
x
:
-0.20030239
,
y
:
-0.0032947473
}
-
{
x
:
-0.19672102
,
y
:
-0.049537703
}
-
{
x
:
-0.074930325
,
y
:
-0.15924858
}
-
{
x
:
0.029255845
,
y
:
-0.15745671
}
-
{
x
:
0.16104655
,
y
:
-0.11953767
}
-
{
x
:
0.18702343
,
y
:
-0.09971093
}
-
{
x
:
0.21567449
,
y
:
-0.028959516
}
-
{
x
:
0.16209309
,
y
:
0.06745669
}
---
!u!1
&1061721880
---
!u!1
&1061721880
GameObject
:
GameObject
:
m_ObjectHideFlags
:
0
m_ObjectHideFlags
:
0
...
...
Assets/Scripts/Bird.cs
浏览文件 @
995c6986
using
System.Collections
;
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine
;
...
@@ -8,9 +9,18 @@ public class Bird : MonoBehaviour
...
@@ -8,9 +9,18 @@ public class Bird : MonoBehaviour
private
Vector3
startPos
;
//小鸟的初始位置
private
Vector3
startPos
;
//小鸟的初始位置
public
float
floatScall
=
1
;
//浮动范围
public
float
floatScall
=
1
;
//浮动范围
public
float
floatRate
=
1
;
//浮动频率
public
float
floatRate
=
1
;
//浮动频率
public
float
gravityScall
=
1
;
//小鸟重力
private
float
currentSpeed
;
//当前小鸟的速度
public
float
downSpeed
=
-
5
;
//正常向下的速度
public
float
jumpSpeed
=
6
;
//起跳时的速度
public
float
reduceSpeed
=
20f
;
//减速度
private
Quaternion
upRotation
=
Quaternion
.
Euler
(
0
,
0
,
25
);
//向上的旋转
private
Quaternion
downRotation
=
Quaternion
.
Euler
(
0
,
0
,-
90
);
//向下的旋转
private
Rigidbody2D
rig
;
//刚体
private
Rigidbody2D
rig
;
//刚体
public
float
force
=
50
;
//力
public
event
Action
<
Collider2D
>
onTrigger
;
//事件:当碰撞触发
private
void
Start
()
private
void
Start
()
{
{
startPos
=
transform
.
position
;
//记录小鸟的初始位置
startPos
=
transform
.
position
;
//记录小鸟的初始位置
...
@@ -23,23 +33,37 @@ public class Bird : MonoBehaviour
...
@@ -23,23 +33,37 @@ public class Bird : MonoBehaviour
transform
.
position
=
startPos
+
Vector3
.
up
*
Mathf
.
Sin
(
Time
.
time
*
floatRate
)
*
floatScall
;
transform
.
position
=
startPos
+
Vector3
.
up
*
Mathf
.
Sin
(
Time
.
time
*
floatRate
)
*
floatScall
;
}
}
public
void
UseGravity
()
{
rig
.
gravityScale
=
gravityScall
;
//设置重力值
}
//小鸟飞和跳,被控制器调用
//小鸟飞和跳,被控制器调用
public
void
Flay
()
public
void
Flay
()
{
{
if
(
Input
.
GetMouseButtonDown
(
0
))
//计算速度
if
(
currentSpeed
>
downSpeed
)
//如果当前速度大于正常向下速度,就让当前速度减小
{
currentSpeed
-=
reduceSpeed
*
Time
.
deltaTime
;
}
//使用速度移动
transform
.
Translate
(
Vector3
.
up
*
currentSpeed
*
Time
.
deltaTime
,
Space
.
World
);
//设置旋转
if
(
currentSpeed
>
0
)
{
transform
.
rotation
=
Quaternion
.
Lerp
(
transform
.
rotation
,
upRotation
,
10f
*
Time
.
deltaTime
);
}
else
if
(
currentSpeed
<-
5.5f
)
{
{
Jump
(
);
transform
.
rotation
=
Quaternion
.
RotateTowards
(
transform
.
rotation
,
downRotation
,
720
*
Time
.
deltaTime
);
}
}
}
}
public
void
Jump
()
public
void
Jump
()
{
{
rig
.
velocity
=
Vector2
.
zero
;
//刚体速度设置为0
currentSpeed
=
jumpSpeed
;
rig
.
AddForce
(
Vector2
.
up
*
force
);
//加一个向上的力
}
//当触发器进入的时候
private
void
OnTriggerEnter2D
(
Collider2D
collision
)
//collision 是对方的碰撞器组件
{
onTrigger
?.
Invoke
(
collision
);
// if (onTrigger!=null) { onTrigger(collision); }
}
}
}
}
Assets/Scripts/GameController.cs
浏览文件 @
995c6986
...
@@ -8,7 +8,41 @@ public class GameController : MonoBehaviour
...
@@ -8,7 +8,41 @@ public class GameController : MonoBehaviour
public
MoveGroup
moveGroup
;
public
MoveGroup
moveGroup
;
public
Bird
bird
;
public
Bird
bird
;
public
GameState
state
=
GameState
.
empty
;
//当前游戏状态
public
GameState
state
=
GameState
.
empty
;
//当前游戏状态
private
int
score
=
0
;
//分数
bool
stop
=
false
;
//小鸟停止下落
private
void
Start
()
{
bird
.
onTrigger
+=
BirdOnTrigger
;
}
private
void
BirdOnTrigger
(
Collider2D
other
)
{
if
(
other
.
name
==
"Score"
)
{
print
(
"加分"
);
score
+=
1
;
}
else
if
(
other
.
name
.
StartsWith
(
"Pipe"
))
{
print
(
"游戏结束"
);
Over
();
}
else
if
(
other
.
name
==
"GroundCollider"
)
{
if
(
state
!=
GameState
.
gameOver
)
//如果游戏之前没有结束,就先结束
{
Over
();
}
stop
=
true
;
}
}
private
void
Over
()
{
moveGroup
.
GetComponent
<
Rigidbody2D
>().
velocity
=
Vector2
.
zero
;
//水管和地板停止移动
state
=
GameState
.
gameOver
;
//切换游戏状态为结束状态
}
private
void
Update
()
private
void
Update
()
{
{
...
@@ -45,7 +79,6 @@ public class GameController : MonoBehaviour
...
@@ -45,7 +79,6 @@ public class GameController : MonoBehaviour
{
{
moveGroup
.
pipGroup
.
SetParent
(
moveGroup
.
transform
);
//把水管设置为移动组的子物体
moveGroup
.
pipGroup
.
SetParent
(
moveGroup
.
transform
);
//把水管设置为移动组的子物体
bird
.
GetComponent
<
Animator
>().
enabled
=
true
;
//开启动画
bird
.
GetComponent
<
Animator
>().
enabled
=
true
;
//开启动画
bird
.
UseGravity
();
//小鸟使用重力
bird
.
Jump
();
bird
.
Jump
();
state
=
GameState
.
palying
;
state
=
GameState
.
palying
;
}
}
...
@@ -53,13 +86,20 @@ public class GameController : MonoBehaviour
...
@@ -53,13 +86,20 @@ public class GameController : MonoBehaviour
//玩的状态
//玩的状态
private
void
Play
()
private
void
Play
()
{
{
bird
.
Flay
();
bird
.
Flay
();
//跳
if
(
Input
.
GetMouseButtonDown
(
0
))
{
bird
.
Jump
();
}
}
}
private
void
GameOver
()
private
void
GameOver
()
{
{
if
(!
stop
)
{
bird
.
Flay
();
}
}
}
}
}
...
@@ -71,6 +111,8 @@ public enum GameState
...
@@ -71,6 +111,8 @@ public enum GameState
gameOver
//游戏结束状态
gameOver
//游戏结束状态
}
}
/*public 公开的哪儿都能访问
/*public 公开的哪儿都能访问
private 私有的只能在本类内部可以访问
private 私有的只能在本类内部可以访问
protected 收保护的,只能在本类内部和子类内部可以访问
protected 收保护的,只能在本类内部和子类内部可以访问
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录