feat: Player script updates - ground check, flip, animations, and study notes

This commit is contained in:
2026-05-25 17:00:17 +08:00
parent 8b196e9343
commit c2b93486c5
17 changed files with 5047 additions and 94 deletions

8
Assets/Animations.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0bfc731052abef54fb83431c06faec18
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,159 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1107 &-7853685596089614426
AnimatorStateMachine:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Base Layer
m_ChildStates:
- serializedVersion: 1
m_State: {fileID: -2999887273125739820}
m_Position: {x: 320, y: 40, z: 0}
- serializedVersion: 1
m_State: {fileID: 8541810184871255671}
m_Position: {x: 315, y: 175, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
m_StateMachineTransitions: {}
m_StateMachineBehaviours: []
m_AnyStatePosition: {x: 50, y: 20, z: 0}
m_EntryPosition: {x: 50, y: 120, z: 0}
m_ExitPosition: {x: 610, y: 110, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: -2999887273125739820}
--- !u!1102 &-2999887273125739820
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: playerIdle
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: -1263164013022993944}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: fe96eea6ebc2c8b4dbe787f4b59ef43f, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1101 &-1263164013022993944
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: isMoving
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 8541810184871255671}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0.5833334
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!91 &9100000
AnimatorController:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Player
serializedVersion: 5
m_AnimatorParameters:
- m_Name: isMoving
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
m_StateMachine: {fileID: -7853685596089614426}
m_Mask: {fileID: 0}
m_Motions: []
m_Behaviours: []
m_BlendingMode: 0
m_SyncedLayerIndex: -1
m_DefaultWeight: 0
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1101 &7343199574911539791
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: isMoving
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -2999887273125739820}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0
m_TransitionOffset: 0
m_ExitTime: 0.625
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &8541810184871255671
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PlayerMove
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 7343199574911539791}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: ac4d453786085a145949201d8c33f0e0, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4cd7b9f753545ba40a639b07336ad421
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 9100000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: PlayerMove
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves:
- serializedVersion: 2
curve:
- time: 0
value: {fileID: 1810491922, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.083333336
value: {fileID: -723117680, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.16666667
value: {fileID: 2013422008, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.25
value: {fileID: -688480063, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.33333334
value: {fileID: 1396573066, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.41666666
value: {fileID: -171298805, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.5
value: {fileID: 911255850, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.5833333
value: {fileID: -1133639880, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
flags: 2
m_SampleRate: 12
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 0
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping:
- {fileID: 1810491922, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: -723117680, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: 2013422008, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: -688480063, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: 1396573066, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: -171298805, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: 911255850, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: -1133639880, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.6666666
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 1
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ac4d453786085a145949201d8c33f0e0
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!74 &7400000
AnimationClip:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: playerIdle
serializedVersion: 7
m_Legacy: 0
m_Compressed: 0
m_UseHighQualityCurve: 1
m_RotationCurves: []
m_CompressedRotationCurves: []
m_EulerCurves: []
m_PositionCurves: []
m_ScaleCurves: []
m_FloatCurves: []
m_PPtrCurves:
- serializedVersion: 2
curve:
- time: 0
value: {fileID: -1750721404, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.1
value: {fileID: 1117037913, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.2
value: {fileID: 684117881, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.3
value: {fileID: -284851867, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.4
value: {fileID: 1153121478, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- time: 0.5
value: {fileID: -816975202, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
attribute: m_Sprite
path:
classID: 212
script: {fileID: 0}
flags: 2
m_SampleRate: 10
m_WrapMode: 0
m_Bounds:
m_Center: {x: 0, y: 0, z: 0}
m_Extent: {x: 0, y: 0, z: 0}
m_ClipBindingConstant:
genericBindings:
- serializedVersion: 2
path: 0
attribute: 0
script: {fileID: 0}
typeID: 212
customType: 23
isPPtrCurve: 1
isIntCurve: 0
isSerializeReferenceCurve: 0
pptrCurveMapping:
- {fileID: -1750721404, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: 1117037913, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: 684117881, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: -284851867, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: 1153121478, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
- {fileID: -816975202, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
m_AnimationClipSettings:
serializedVersion: 2
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.6
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
m_HasAdditiveReferencePose: 0
m_LoopTime: 1
m_LoopBlend: 0
m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0
m_LoopBlendPositionXZ: 0
m_KeepOriginalOrientation: 0
m_KeepOriginalPositionY: 1
m_KeepOriginalPositionXZ: 0
m_HeightFromFeet: 0
m_Mirror: 0
m_EditorCurves: []
m_EulerEditorCurves: []
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events: []

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fe96eea6ebc2c8b4dbe787f4b59ef43f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 7400000
userData:
assetBundleName:
assetBundleVariant:

8
Assets/Graphics.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d94a2887da7020e48bd213ae515c5bb4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -2,16 +2,93 @@ using UnityEngine;
public class Player : MonoBehaviour
{
public Rigidbody2D rb;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
private Animator anim;
private Rigidbody2D rb;
[Header("Movement details")]
[SerializeField] private float moveSpeed = 4.58f;
[SerializeField] private float jumpForce = 12;
private bool facingRight = true;
private float xInput;
[Header("Collision details")]
[SerializeField] private float groundCheckDistance;
[SerializeField] private LayerMask whatIsGround;
private bool isGrounded;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponentInChildren<Animator>();
}
// Update is called once per frame
void Update()
private void Update()
{
rb.linearVelocity = new Vector2(Input.GetAxis("Horizontal"), rb.linearVelocityY);
HandleCollision();
HandleInput();
HandleMovement();
HandleAnimations();
HandleFlip();
}
private void HandleInput()
{
xInput = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.K))
{
jump();
}
}
private void HandleAnimations()
{
bool isMoving = rb.linearVelocity.x != 0;
anim.SetBool("isMoving", isMoving);
}
private void HandleMovement()
{
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
}
private void jump()
{
if (isGrounded)
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
}
}
private void HandleCollision()
{
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundCheckDistance, whatIsGround);
}
private void HandleFlip()
{
if(rb.linearVelocity.x > 0 && facingRight == false)
{
Flip();
}
else if (rb.linearVelocity.x < 0 && facingRight == true)
{
Flip();
}
}
private void Flip()
{
transform.Rotate(0, 180, 0);
facingRight = !facingRight;
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(transform.position, transform.position + new Vector3(0, -groundCheckDistance));
}
}

View File

@@ -128,10 +128,9 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 420449211}
- component: {fileID: 420449210}
- component: {fileID: 420449209}
- component: {fileID: 420449212}
- component: {fileID: 420449213}
- component: {fileID: 420449214}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
@@ -152,9 +151,9 @@ Rigidbody2D:
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDamping: 0
m_LinearDamping: 0.5
m_AngularDamping: 0.05
m_GravityScale: 5
m_GravityScale: 3.5
m_Material: {fileID: 6200000, guid: f314db0ef0ce38e42ac269eab083ad71, type: 2}
m_IncludeLayers:
serializedVersion: 2
@@ -165,66 +164,7 @@ Rigidbody2D:
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!212 &420449210
SpriteRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
m_Constraints: 4
--- !u!4 &420449211
Transform:
m_ObjectHideFlags: 0
@@ -234,14 +174,33 @@ Transform:
m_GameObject: {fileID: 420449208}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.08, y: 3.05, z: 0}
m_LocalPosition: {x: 4.01, y: -1.26, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Children:
- {fileID: 1414990379}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!58 &420449212
CircleCollider2D:
--- !u!114 &420449213
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cb2ed43676cd08e4da098563b4cef1e9, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Player
moveSpeed: 8
jumpForce: 12
groundCheckDistance: 1.4
whatIsGround:
serializedVersion: 2
m_Bits: 64
--- !u!70 &420449214
CapsuleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
@@ -274,21 +233,9 @@ CircleCollider2D:
m_UsedByEffector: 0
m_CompositeOperation: 0
m_CompositeOrder: 0
m_Offset: {x: 0, y: 0}
m_Radius: 0.5
--- !u!114 &420449213
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cb2ed43676cd08e4da098563b4cef1e9, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Player
rb: {fileID: 420449209}
m_Offset: {x: 0, y: -0.3}
m_Size: {x: 0.778394, y: 2.101978}
m_Direction: 0
--- !u!1 &454696404
GameObject:
m_ObjectHideFlags: 0
@@ -300,7 +247,8 @@ GameObject:
- component: {fileID: 454696406}
- component: {fileID: 454696405}
- component: {fileID: 454696407}
m_Layer: 0
- component: {fileID: 454696408}
m_Layer: 6
m_Name: Platform
m_TagString: Untagged
m_Icon: {fileID: 0}
@@ -427,6 +375,33 @@ BoxCollider2D:
m_AutoTiling: 0
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!50 &454696408
Rigidbody2D:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 454696404}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 5
m_LinearDamping: 0
m_AngularDamping: 2
m_GravityScale: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 7
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
@@ -533,7 +508,7 @@ Camera:
far clip plane: 1000
field of view: 34
orthographic: 1
orthographic size: 5
orthographic size: 8
m_Depth: -1
m_CullingMask:
serializedVersion: 2
@@ -648,6 +623,120 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1414990378
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1414990379}
- component: {fileID: 1414990380}
- component: {fileID: 1414990381}
m_Layer: 0
m_Name: Animator
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1414990379
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1414990378}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.5, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 420449211}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &1414990380
SpriteRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1414990378}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Sprite: {fileID: -1750721404, guid: 2a192e342a6409b4d9677ef04a238b79, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 4.3125, y: 2.75}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
--- !u!95 &1414990381
Animator:
serializedVersion: 7
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1414990378}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 4cd7b9f753545ba40a639b07336ad421, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_AnimatePhysics: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0

8
Assets/_Recovery.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c62c6dafbcb385048a9ba5c55eb66679
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

687
Assets/_Recovery/0.unity Normal file
View File

@@ -0,0 +1,687 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 10
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 3
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
m_BakeOnSceneLoad: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 0
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 1
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 512
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 1
m_PVRDenoiserTypeDirect: 1
m_PVRDenoiserTypeIndirect: 1
m_PVRDenoiserTypeAO: 1
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 3
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
buildHeightMesh: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &420449208
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 420449211}
- component: {fileID: 420449210}
- component: {fileID: 420449209}
- component: {fileID: 420449212}
- component: {fileID: 420449213}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!50 &420449209
Rigidbody2D:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDamping: 0
m_AngularDamping: 0.05
m_GravityScale: 5
m_Material: {fileID: 6200000, guid: f314db0ef0ce38e42ac269eab083ad71, type: 2}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!212 &420449210
SpriteRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
--- !u!4 &420449211
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.08, y: 3.05, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!58 &420449212
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_Enabled: 1
serializedVersion: 3
m_Density: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_ForceSendLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ForceReceiveLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ContactCaptureLayers:
serializedVersion: 2
m_Bits: 4294967295
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_UsedByEffector: 0
m_CompositeOperation: 0
m_CompositeOrder: 0
m_Offset: {x: 0, y: 0}
m_Radius: 0.5
--- !u!114 &420449213
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 420449208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cb2ed43676cd08e4da098563b4cef1e9, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::Player
rb: {fileID: 0}
moveSpeed: 3.5
--- !u!1 &454696404
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 454696406}
- component: {fileID: 454696405}
- component: {fileID: 454696407}
- component: {fileID: 454696408}
m_Layer: 0
m_Name: Platform
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!212 &454696405
SpriteRenderer:
serializedVersion: 2
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 454696404}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 0.23538396, g: 0.1986917, b: 0.8962264, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_SpriteSortPoint: 0
--- !u!4 &454696406
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 454696404}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.14, y: -3.14, z: 0}
m_LocalScale: {x: 16.002186, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &454696407
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 454696404}
m_Enabled: 1
serializedVersion: 3
m_Density: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_ForceSendLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ForceReceiveLayers:
serializedVersion: 2
m_Bits: 4294967295
m_ContactCaptureLayers:
serializedVersion: 2
m_Bits: 4294967295
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_UsedByEffector: 0
m_CompositeOperation: 0
m_CompositeOrder: 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: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!50 &454696408
Rigidbody2D:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 454696404}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 5
m_LinearDamping: 0
m_AngularDamping: 2
m_GravityScale: 1
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 7
--- !u!1 &519420028
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 519420032}
- component: {fileID: 519420031}
- component: {fileID: 519420029}
- component: {fileID: 519420030}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &519420029
AudioListener:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
--- !u!114 &519420030
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_RenderShadows: 1
m_RequiresDepthTextureOption: 2
m_RequiresOpaqueTextureOption: 2
m_CameraType: 0
m_Cameras: []
m_RendererIndex: -1
m_VolumeLayerMask:
serializedVersion: 2
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
m_ClearDepth: 1
m_AllowXRRendering: 1
m_AllowHDROutput: 1
m_UseScreenCoordOverride: 0
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_TaaSettings:
m_Quality: 3
m_FrameInfluence: 0.1
m_JitterScale: 1
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
m_Version: 2
--- !u!20 &519420031
Camera:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_Iso: 200
m_ShutterSpeed: 0.005
m_Aperture: 16
m_FocusDistance: 10
m_FocalLength: 50
m_BladeCount: 5
m_Curvature: {x: 2, y: 11}
m_BarrelClipping: 0.25
m_Anamorphism: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 34
orthographic: 1
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 0
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &519420032
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &619394800
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 619394802}
- component: {fileID: 619394801}
m_Layer: 0
m_Name: Global Light 2D
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &619394801
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 619394800}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 073797afb82c5a1438f328866b10b3f0, type: 3}
m_Name:
m_EditorClassIdentifier:
m_ComponentVersion: 2
m_LightType: 4
m_BlendStyleIndex: 0
m_FalloffIntensity: 0.5
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Intensity: 1
m_LightVolumeIntensity: 1
m_LightVolumeEnabled: 0
m_ApplyToSortingLayers: 00000000
m_LightCookieSprite: {fileID: 0}
m_DeprecatedPointLightCookieSprite: {fileID: 0}
m_LightOrder: 0
m_AlphaBlendOnOverlap: 0
m_OverlapOperation: 0
m_NormalMapDistance: 3
m_NormalMapQuality: 2
m_UseNormalMap: 0
m_ShadowsEnabled: 0
m_ShadowIntensity: 0.75
m_ShadowSoftness: 0
m_ShadowSoftnessFalloffIntensity: 0.5
m_ShadowVolumeIntensityEnabled: 0
m_ShadowVolumeIntensity: 0.75
m_LocalBounds:
m_Center: {x: 0, y: -0.00000011920929, z: 0}
m_Extent: {x: 0.9985302, y: 0.99853027, z: 0}
m_PointLightInnerAngle: 360
m_PointLightOuterAngle: 360
m_PointLightInnerRadius: 0
m_PointLightOuterRadius: 1
m_ShapeLightParametricSides: 5
m_ShapeLightParametricAngleOffset: 0
m_ShapeLightParametricRadius: 1
m_ShapeLightFalloffSize: 0.5
m_ShapeLightFalloffOffset: {x: 0, y: 0}
m_ShapePath:
- {x: -0.5, y: -0.5, z: 0}
- {x: 0.5, y: -0.5, z: 0}
- {x: 0.5, y: 0.5, z: 0}
- {x: -0.5, y: 0.5, z: 0}
--- !u!4 &619394802
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 619394800}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
m_Roots:
- {fileID: 519420032}
- {fileID: 619394802}
- {fileID: 454696406}
- {fileID: 420449211}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1868cf6f652845d4bace7e07c4385c9f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,7 @@
%TAG !u! tag:unity3d.com,2011:
--- !u!78 &1
TagManager:
serializedVersion: 2
serializedVersion: 3
tags: []
layers:
- Default
@@ -11,7 +11,7 @@ TagManager:
-
- Water
- UI
-
- Ground
-
-
-
@@ -41,3 +41,5 @@ TagManager:
- name: Default
uniqueID: 0
locked: 0
m_RenderingLayers:
- Default

175
Q&A.md Normal file
View File

@@ -0,0 +1,175 @@
# Q&A
> 学习过程中遇到的问题记录
---
## Q1为什么保留 `rb.linearVelocity.y` 不会导致 Player 上下移动,而改变 `x` 就会左右移动?
### 关键理解
`rb.linearVelocity` 每一帧都被**完整重新赋值**X 和 Y 的来源不同决定了它们的行为不同。
### X 轴:由输入主动控制
```csharp
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
// ^^^^^^^^^^^^^^^^
// 这部分的数值由你决定
```
| 操作 | `xInput` | `velocity.x` | 效果 |
|------|:--------:|:------------:|:----:|
| 按 A / ← | -1 | -3.5 | 向左移动 |
| 松开 | 0 | 0 | 停止 |
| 按 D / → | 1 | 3.5 | 向右移动 |
每次赋值X 都被设为**输入决定的明确值**,所以会立刻产生/停止移动。
### Y 轴:物理系统已经在运行
`rb.linearVelocity.y` 不是空的,它已经是物理引擎当前帧算好的结果:
| 状态 | `velocity.y` 实际值 | 保留后效果 |
|------|:-------------------:|:----------:|
| 站地上 | ≈ 0 | 不动(地面碰撞把 y 锁为 0 |
| 下落中 | < 0重力累加 | 继续下落 |
| 跳起后 | > 0 → 逐渐减小 | 上升 → 减速 → 下落 |
保留 Y 的本质是 **"不去干涉"** 物理系统对垂直运动的控制,而不是"主动让角色上下动"。
### 反例:写死 Y 会怎样?
```csharp
rb.linearVelocity = new Vector2(xInput * moveSpeed, 0); // ❌
```
- 重力被清零 → 角色不会下落,飘在空中
- 跳跃被清零 → 跳不起来
- 地面碰撞结果被覆盖 → 可能会卡进地面
### 一句话总结
> X 轴 velocity 是你主动赋值来**命令移动**Y 轴 velocity 是物理系统**正在运行的结果**,保留它只是不去搞破坏。
---
*2026-05-23*
## Q2跳跃时直接覆盖 Y 为 `jumpForce`,和之前说的"保留 Y"不矛盾吗?为什么不用 `y + jumpForce`
### 问题背景
之前的 Q&A 说"保留 `rb.linearVelocity.y` 不去干涉物理系统",但跳跃代码却直接覆盖:
```csharp
// 平时移动:保留 Y不去干扰物理
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
// 跳跃时:覆盖 Y
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
```
直觉上会觉得应该写成 `rb.linearVelocity.y + jumpForce` 才对。
### 核心解答
**场景不同,原则不同:**
| 场景 | 对 Y 的操作 | 意图 |
|------|:----------:|:----:|
| 左右移动 | 保留 Y | **不管**物理系统的事 |
| 跳跃 | 覆盖 Y = jumpForce | **主动干预**,跳跃本身就是这个干预 |
平时保留 Y 是因为"不需要管 Y",跳跃覆盖 Y 是因为"现在就要动 Y"。
### 为什么用 `= jumpForce` 而不是 `+= jumpForce`
站在平地时 `velocity.y ≈ 0`,两者结果一样。但在以下情况加法会出问题:
| 场景 | velocity.y 当前值 | `= jumpForce` | `+= jumpForce` | 哪个合理 |
|------|:--:|:--:|:--:|:--:|
| 平地站着 | ≈ 0 | = 8 ✅ | = 8 ✅ | 一样 |
| 在上升平台上跳 | > 0如 +3 | = 8 ✅ | = 11 ❌ 异常高 | `=` |
| 下落中误触跳跃 | < 0如 -5 | = 8 ✅ | = 3 ❌ 跳不起来 | `=` |
- **`= jumpForce`** — 每次跳跃高度一致,可预测 ✅
- **`+= jumpForce`** — 跳跃高度受当前 Y 速度影响,结果不稳定 ❌
### 总结
> 保留 Y = **不想管**物理的事
> 覆盖 Y = **正在主动做跳跃这件事**
> 用 `=` 保证每次跳跃可预测,用 `+=` 反而会让跳跃高度飘忽不定
---
## Q3二段跳可以从哪些方面入手设计
### 前提
第九次更新已经实现了接地检测(`isGrounded`),跳跃被限制为"只有在地上才能跳"。在此基础上扩展二段跳,需要考虑以下几个维度:
### 1. 核心机制 —— 如何判断"能不能跳"
**计数器方案(推荐,可扩展性强):**
```
jumpCount = 允许的跳跃次数(例如 2
remainingJumps = 当前剩余次数
想跳时:
1. 检查 remainingJumps > 0
2. 是 → 跳remainingJumps--
3. 否 → 不跳
落地时:
重置 remainingJumps = jumpCount
```
- 优点:改为 3 段跳、4 段跳只需改一个数字,代码不用动
- 问自己:`remainingJumps` 什么时候扣?什么时候重置?
### 2. 重置时机 —— "跳"这个状态何时结束
核心问题:**二段跳的"次数"在什么时候补回来?**
| 方案 | 行为 | 手感 |
|------|------|------|
| 落地重置 | 碰到地面才能再次二段跳 | 标准平台跳跃,最常用 |
| 接触墙壁重置 | 贴墙也能补跳 | 适合有爬墙机制的游戏 |
| 每 X 秒恢复一次 | 空中待一会儿又能跳 | 节奏较怪,很少用 |
> 当前项目有 `isGrounded`,落地重置是最自然的选择。
### 3. 跳跃力设计 —— 二段跳应该和第一段一样高吗?
| 方案 | 效果 | 代表游戏 |
|------|------|---------|
| 相同 jumpForce | 两段跳一样高,手感直接 | 空洞骑士(部分技能)|
| 稍弱(如 jumpForce × 0.8| 第二段更低,更真实 | 蔚蓝 Celeste |
| 固定低值 | 二段跳只用来"续一下" | 大乱斗 |
> 可以先设两个独立参数 `jumpForce` 和 `doubleJumpForce`,分别调。
### 4. 需要考虑的边界问题
| 问题 | 说明 |
|------|------|
| **走边缘掉落** | 从平台边缘走下来(没按跳),空中能二段跳吗?通常可以 |
| **没用第一段跳** | 跳过一次后空中还能跳一次?还是说必须先用一次跳?取决于设计 |
| **Coyote Time** | 离开地面后很短时间(如 0.1s)内按跳还算落地跳吗?和剩余次数如何叠加? |
| **动画反馈** | 二段跳时播放不同的动画(如翻转、翅膀),让玩家感知到"我用了二段跳" |
| **只能一次** | 二段跳用完没落地之前,不能再获得跳跃次数 |
### 5. 建议的切入顺序
1. 先把计数器机制做出来(`jumpCount` / `remainingJumps`
2. `jump()` 中把 `if(isGrounded)` 改为 `if(remainingJumps > 0)`
3. 落地时重置 `remainingJumps = jumpCount`
4.`doubleJumpForce` 找手感
5. 加动画区分一段跳和二段跳
---
*2026-05-25*

785
StudyNotes.md Normal file
View File

@@ -0,0 +1,785 @@
# Unity RPG 学习笔记
> 📅 创建于 2026-05-23
> 🎯 按时间顺序记录学习过程
---
## 2026-05-23 · 第一次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
public float xInput;
private void Update()
// 旧的移动方式
{
xInput = Input.GetAxisRaw("Horizontal");
}
}
```
### 知识点
#### 1. `MonoBehaviour` 继承
- Unity 中挂载到 GameObject 的脚本必须继承 `MonoBehaviour`
- 继承后可使用生命周期方法(`Update``Start``Awake` 等)。
#### 2. `public` 字段暴露到 Inspector
- `public float xInput;` 会在 Inspector 面板中可见、可编辑。
- 公开字段会被序列化,保存到场景/预制体数据中。
#### 3. `Update()` 生命周期
- 每帧调用一次,帧率越高调用越频繁。
- 适合处理**输入检测**、**持续移动**等实时逻辑。
#### 4. `Input.GetAxisRaw("Horizontal")` vs `GetAxis("Horizontal")`
| 方法 | 返回值变化 | 手感 |
|---|---|---|
| `GetAxis` | 0→1 平滑过渡(加减速曲线) | 柔和,有惯性 |
| `GetAxisRaw` | 瞬间跳变 -1/0/1 | 灵敏,即时响应 |
- `"Horizontal"` 默认绑定A/D、←/→、手柄左摇杆 X 轴。
#### 5. `Input` 类常用方法
- `GetAxis()` / `GetAxisRaw()` — 轴向输入
- `GetKey()` / `GetKeyDown()` / `GetKeyUp()` — 按键检测
- `GetMouseButton()` — 鼠标检测
---
## 2026-05-23 · 第二次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
public Rigidbody2D rb;
public float moveSpeed = 3.5f;
public float xInput;
private void Update()
// 旧的移动方式
{
xInput = Input.GetAxisRaw("Horizontal");
rb.linearVelocity = new Vector2 (xInput * moveSpeed, rb.linearVelocity.y);
}
}
```
### 新增知识点
#### 1. `Rigidbody2D` 组件
- Unity 2D 物理引擎的核心组件,赋予物体物理属性(质量、重力、速度等)。
- 通过 `public Rigidbody2D rb;` 声明后,需在 Inspector 中拖入对应的 Rigidbody2D 组件进行绑定。
- 凡是需要物理模拟(重力、碰撞、速度)的 2D 物体都应挂载此组件。
#### 2. `linearVelocity` 属性(物理移动)
- `Rigidbody2D.linearVelocity` 表示刚体的**线性速度**Vector2 类型)。
- 直接赋值可以瞬间改变物体速度,实现物理驱动的移动。
- 这是旧版 `velocity` 属性的新命名Unity 2023+ 推荐使用 `linearVelocity`)。
- 相比直接改 `Transform.position`,物理移动能正确参与碰撞检测。
#### 3. `Vector2` 构造函数
- `new Vector2(x, y)` 创建一个二维向量。
- `x` 控制水平移动:`xInput * moveSpeed`,按方向键时值为 ±3.5f,松开时为 0。
- `y` 保持当前垂直速度:`rb.linearVelocity.y`,避免干扰重力/跳跃。
- ⚠️ 注意:代码中 `new Vector2 (...)` 括号前多了一个空格,虽不影响编译但建议去掉。
#### 4. 物理移动 vs Transform 移动(对比)
| 方式 | 原理 | 碰撞检测 | 适用场景 |
|---|---|---|---|
| `rb.linearVelocity` | 修改刚体速度 | ✅ 物理正确 | 平台跳跃、推箱子等 |
| `transform.Translate` | 直接改位置 | ❌ 可能穿模 | 纯位移、无物理需求 |
#### 5. 移动逻辑解析
```
按下 A / ← → xInput = -1 → velocity.x = -3.5 → 向左移动
松开按键 → xInput = 0 → velocity.x = 0 → 停止
按下 D / → → xInput = 1 → velocity.x = 3.5 → 向右移动
```
---
## 2026-05-24 · 第三次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody2D rb;
[SerializeField] private float moveSpeed = 3.5f;
private float xInput;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
// 旧的移动方式
{
xInput = Input.GetAxisRaw("Horizontal");
rb.linearVelocity = new Vector2 (xInput * moveSpeed, rb.linearVelocity.y);
}
}
```
### 本次改动 · 新增知识点
#### 1. `private` 字段与封装
- 之前字段全用 `public`,现在改为 `private`
- **原则:** 不需要外部访问的字段应该设为私有,遵循封装原则,防止意外修改。
- `xInput` 改为 `private` 很合理——它只是内部计算用的临时值Inspector 中没必要看到。
#### 2. `[SerializeField]` 特性
- 问题:字段设为 `private`Inspector 面板中就看不到了。
- 解决:加 `[SerializeField]` 可以让**私有字段也显示在 Inspector 中**。
- 这样就做到了「Inspector 可调,代码不可外部访问」的最佳实践。
- `moveSpeed` 用了这个特性——可以在编辑器里调速度,但其他脚本不能随便改。
#### 3. `Awake()` 生命周期方法
- `Awake()` 在脚本实例加载时调用,**比 `Start()` 更早**,且只调用一次。
- Unity 生命周期顺序:`Awake()``OnEnable()``Start()``Update()` → ...
- 适合做**组件引用的初始化**(获取自己身上的组件、初始化变量等)。
-`Start()` 的区别:`Awake` 在所有脚本的 `Start` 之前执行完,适合组件间的依赖初始化。
#### 4. `GetComponent<T>()` 方法
- 从当前 GameObject 上获取指定类型的组件引用。
- `rb = GetComponent<Rigidbody2D>();` — 自动找到同物体上的 Rigidbody2D 组件并赋值。
- 这是比手动在 Inspector 中拖拽更优雅的方式——**减少人为忘记绑定的风险**。
- 前提:该组件必须挂载在同一个 GameObject 上。
#### 5. 对比:手动拖拽 vs GetComponent
| 方式 | 字段类型 | 优点 | 缺点 |
|---|---|---|---|
| Inspector 拖拽 | `public` | 可以绑定其他物体上的组件 | 容易忘记拖,运行时 NullReference |
| `GetComponent` | `private` | 不会忘,代码自动获取 | 只能获取同一物体上的组件 |
> 💡 当前代码中 `rb` 用的是 `GetComponent`,因为 Rigidbody2D 肯定在 Player 自己身上,很合适。
### 使用建议
- 自己身上的组件 → `GetComponent` + `Awake`
- 需要引用其他物体的组件 → `public`(或 `[SerializeField] private`+ Inspector 拖拽
---
## 2026-05-24 · 第四次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody2D rb;
[SerializeField] private float moveSpeed = 3.5f;
private float xInput;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
// 旧的移动方式
{
xInput = Input.GetAxisRaw("Horizontal");
rb.linearVelocity = new Vector2 (xInput * moveSpeed, rb.linearVelocity.y);
// 按K
if (Input.GetKey(KeyCode.K))
{
Debug.Log("holding K");
}
// 按下K
if (Input.GetKeyDown(KeyCode.K))
{
Debug.Log("pressed K");
}
}
}
```
### 本次改动 · 新增知识点
#### 1. 按键检测三剑客:`GetKey` / `GetKeyDown` / `GetKeyUp`
| 方法 | 触发时机 | 返回值 | 典型用途 |
|---|---|---|---|
| `Input.GetKey(KeyCode)` | 按键**按住**期间 | 每帧 `true` | 持续开火、加速跑 |
| `Input.GetKeyDown(KeyCode)` | 按键**按下**的那一帧 | 只 `true` 一次 | 跳跃、菜单确认 |
| `Input.GetKeyUp(KeyCode)` | 按键**松开**的那一帧 | 只 `true` 一次 | 蓄力释放、弹起 |
> ⚡ 记忆口诀:`GetKey` = 按住不放,`GetKeyDown` = 点一下,`GetKeyUp` = 松开那一刻。
#### 2. `KeyCode` 枚举
-`KeyCode.K` 代替字符串 `"k"`避免拼写错误IDE 有自动补全。
- 常用按键:`KeyCode.Space`(空格)、`KeyCode.Escape``KeyCode.W/A/S/D``KeyCode.Mouse0`(鼠标左键)。
#### 3. `Debug.Log()` 调试输出
- 向 Unity 控制台Console输出消息调试必备。
- `Debug.Log("xxx")` — 普通信息
- `Debug.LogWarning("xxx")` — 警告(黄色)
- `Debug.LogError("xxx")` — 错误(红色,会暂停编辑器播放)
#### 4. 代码验证思路
当前代码跑起来后的效果:
- 按住 K → 控制台疯狂刷 "holding K"(每帧一条)
- 敲一下 K → 只出现一条 "pressed K"
- 通过这个对比就能直观理解 `GetKey``GetKeyDown` 的区别 ✅
---
## 2026-05-24 · 第五次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody2D rb;
[SerializeField] private float moveSpeed = 3.5f;
[SerializeField] private float jumpForce = 8;
private float xInput;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
// 旧的移动方式
{
xInput = Input.GetAxisRaw("Horizontal");
rb.linearVelocity = new Vector2 (xInput * moveSpeed, rb.linearVelocity.y);
if (Input.GetKeyDown(KeyCode.K))
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
}
}
}
```
### 本次改动 · 新增知识点
#### 1. 跳跃实现原理
- 跳跃 = 给刚体的 **Y 轴速度**一个瞬间向上的值。
- `rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);`
- X 保持不变:角色在空中仍能左右移动
- Y 覆盖为 `jumpForce`(正数 = 向上)
- 之后重力会自然把 Y 速度拉回负值,形成"上升→下落"的弧线。
#### 2. 为什么跳跃用 `GetKeyDown` 而不是 `GetKey`
- `GetKeyDown` — 只在按下那一帧触发 → 按一次跳一次 ✅
- `GetKey` — 按住期间每帧都触发 → 角色会一直往上飞 ❌
- 跳跃是一次性动作,必须用 `GetKeyDown`
#### 3. `jumpForce` 参数调优
- `jumpForce = 8` 是目前的值,可以根据手感调整:
- 太小 → 跳不起来
- 太大 → 飞出屏幕
- 配合 Rigidbody2D 的 **Gravity Scale**(重力缩放)一起调,效果更好。
- Gravity Scale 越大 → 下落越快 → 跳跃手感更"重"
- Gravity Scale 越小 → 轻飘飘(适合太空/月球感)
#### 4. 当前完整移动逻辑图
```
┌─────────────────────────────────────────┐
│ Update() │
├─────────────────────────────────────────┤
│ xInput = GetAxisRaw("Horizontal") │
│ ↓ │
│ velocity.x = xInput × moveSpeed │ ← 左右移动(每帧)
│ velocity.y = 保持原来的 y │
│ ↓ │
│ if GetKeyDown(K) │
│ velocity.y = jumpForce │ ← 跳跃(按下瞬间)
└─────────────────────────────────────────┘
```
> ⚠️ 当前跳跃没有接地检测,角色可以在空中无限跳跃。后续可以加 `isGrounded` 判断来限制。
---
## 2026-05-24 · 第六次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
private Animator anim;
private Rigidbody2D rb;
[SerializeField] private float moveSpeed = 3.5f;
[SerializeField] private float jumpForce = 8;
private float xInput;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponentInChildren<Animator>();
}
private void Update()
{
HandleInput();
HandleMovement();
HandleAnimations();
}
private void HandleInput()
{
xInput = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.K))
{
jump();
}
}
private void HandleMovement()
{
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
}
private void HandleAnimations()
{
bool isMoving = rb.linearVelocity.x != 0;
anim.SetBool("isMoving", isMoving);
}
private void jump()
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
}
}
```
### 本次改动 · 新增知识点
#### 1. 代码重构:拆分 Update()
- 之前 `Update()` 里什么都混在一起,现在拆成三个职责明确的方法:
| 方法 | 职责 |
|---|---|
| `HandleInput()` | 读取玩家输入,触发相应动作 |
| `HandleMovement()` | 根据输入计算并应用速度 |
| `HandleAnimations()` | 根据状态更新动画参数 |
- 好处:易读、易改、易扩展。比如以后加攻击,加一个 `HandleCombat()` 即可。
#### 2. `Animator` 组件与动画控制
- `Animator` 是 Unity 的动画状态机组件,控制角色动画的播放。
- `GetComponentInChildren<Animator>()` — 从**子物体**上获取 Animator。
- 因为 Animator 通常挂在角色模型的子物体上,而不是 Player 根物体。
- 控制动画的方式:通过 `SetBool` / `SetFloat` / `SetTrigger` 等方法修改 Animator 参数。
#### 3. `anim.SetBool("isMoving", value)`
- 在 Animator 窗口中预先创建 `isMoving` 参数Bool 类型)。
- 代码中设置这个参数 → Animator 根据状态切换动画Idle ↔ Run
- `isMoving = rb.linearVelocity.x != 0`:水平速度不为 0 就是移动中。
```
isMoving = false → Idle 动画
isMoving = true → Run 动画
```
#### 4. Animator 参数类型对比
| 类型 | 方法 | 用途 |
|---|---|---|
| Bool | `SetBool("name", true/false)` | 二元状态:跑/不跑、地面/空中 |
| Float | `SetFloat("name", 值)` | 连续值:速度、方向 |
| Trigger | `SetTrigger("name")` | 一次性触发:攻击、受伤、死亡 |
| Int | `SetInteger("name", 值)` | 整数状态:武器序号、连击段数 |
#### 5. `GetComponent` vs `GetComponentInChildren`
| 方法 | 搜索范围 | 示例 |
|---|---|---|
| `GetComponent<T>()` | 当前物体 | 获取 Player 上的 Rigidbody2D |
| `GetComponentInChildren<T>()` | 当前物体 + 所有子物体 | 获取模型子物体上的 Animator |
| `GetComponentInParent<T>()` | 当前物体 + 所有父物体 | 少用,偶尔反向查找 |
#### 6. 当前架构图
```
Player (MonoBehaviour)
├── Awake()
│ ├── rb = GetComponent<Rigidbody2D>()
│ └── anim = GetComponentInChildren<Animator>()
└── Update()
├── HandleInput() → 读取按键,调用 jump()
├── HandleMovement() → 设置 velocity
└── HandleAnimations() → 设置 isMoving 驱动动画
```
---
## 2026-05-24 · 第七次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
private Animator anim;
private Rigidbody2D rb;
[SerializeField] private float moveSpeed = 3.5f;
[SerializeField] private float jumpForce = 8;
private float xInput;
[SerializeField] private bool facingRight = true;
// ... Awake、Update、HandleInput、HandleMovement、HandleAnimations、jump 同上 ...
[ContextMenu("Flip")]
private void Flip()
{
transform.Rotate(0, 180, 0);
facingRight = !facingRight;
}
}
```
### 本次改动 · 新增知识点
#### 1. `[ContextMenu]` 特性 —— 测试利器
- 给方法加上 `[ContextMenu("显示名称")]` 后,可以在 Inspector 中右键组件直接调用。
- **非常适合在编辑器中手动测试某个功能**,不需要写额外的测试代码。
```
用法:
1. 选中挂载 Player 脚本的 GameObject
2. 在 Inspector 中找到 Player 组件,右键
3. 菜单中出现 "Flip" → 点击即可执行 Flip() 方法
```
#### 2. `transform.Rotate(x, y, z)` —— 旋转物体
- `transform.Rotate(0, 180, 0)` → 绕 Y 轴旋转 180°即**水平翻转**。
- 三个参数分别对应 X / Y / Z 轴旋转(欧拉角,单位:度)。
- 绕 Y 轴旋转 180° 是 2D 游戏中最常用的翻转方式(让角色面朝另一个方向)。
| 旋转 | 效果 |
|---|---|
| `Rotate(0, 0, 0)` | 面朝右 |
| `Rotate(0, 180, 0)` | 面朝左 |
#### 3. `facingRight` 方向追踪
- `private bool facingRight = true;` 记录当前朝向。
- `[SerializeField]` 让它在 Inspector 中可见,方便调试时观察。
- `facingRight = !facingRight;` 每次翻转时取反,保持状态同步。
- 后续可根据 `facingRight` 决定子弹发射方向、攻击判定范围等。
#### 4. `ContextMenu` vs 其他调用方式
| 方式 | 何时用 |
|---|---|
| `[ContextMenu]` | 编辑器里手动测试某个功能 |
| `Update()` 中调用 | 运行时每帧自动执行 |
| `Button`UI| 玩家通过游戏界面触发 |
> 💡 `[ContextMenu]` 即使方法是 `private` 也能调用,非常适合调试。
---
## 2026-05-25 · 第八次更新
**文件:** `Assets/Player.cs`
```csharp
using UnityEngine;
public class Player : MonoBehaviour
{
private Animator anim;
private Rigidbody2D rb;
[SerializeField] private float moveSpeed = 4.58f;
[SerializeField] private float jumpForce = 8;
private float xInput;
[SerializeField] private bool facingRight = true;
// ... Awake 同上 ...
private void Update()
{
HandleInput();
HandleMovement();
HandleAnimations();
HandleFlip(); // ← 新增
}
// ... HandleInput、HandleMovement、HandleAnimations、jump 同上 ...
private void HandleFlip()
{
if(rb.linearVelocity.x > 0 && facingRight == false)
{
Flip();
}
else if (rb.linearVelocity.x < 0 && facingRight == true)
{
Flip();
}
}
private void Flip()
{
transform.Rotate(0, 180, 0);
facingRight = !facingRight;
}
}
```
### 本次改动 · 新增知识点
#### 1. `HandleFlip()` —— 自动转向逻辑
- 之前 `Flip()` 只能通过 `[ContextMenu]` 手动调用,现在改成**运行时自动翻转**。
- 核心思路:当角色**移动方向**与**当前朝向**不一致时,执行翻转。
#### 2. 翻转判断逻辑拆解
```
向右移动 (velocity.x > 0) 且 面朝左 (facingRight == false) → 翻转
向左移动 (velocity.x < 0) 且 面朝右 (facingRight == true) → 翻转
其他情况(静止、方向已一致) → 不翻转
```
| 速度方向 | facingRight | 需要翻转?|
|---|---|---|
| 向右 (>0) | true面朝右| ❌ 方向一致 |
| 向右 (>0) | false面朝左| ✅ 翻过来 |
| 向左 (<0) | true面朝右| ✅ 翻过来 |
| 向左 (<0) | false面朝左| ❌ 方向一致 |
| 静止 (=0) | 任意 | ❌ 不动不翻 |
#### 3. 为什么用 `facingRight` 而不是直接每帧翻转
- 如果每帧都根据速度方向直接翻转(`if velocity.x > 0 → 右else → 左`),会导致:
- 静止时角色朝向不确定velocity.x = 0 时往哪边?)
- 可能每帧都在调用 `Rotate`,浪费性能
-`facingRight` 做**脏标记dirty flag**:只在需要翻转时才翻,静止时保持上次朝向。
#### 4. `[ContextMenu]` 的移除
- 上一次 `Flip()` 上挂了 `[ContextMenu("Flip")]` 用于手动测试。
- 现在翻转逻辑已集成到 `Update` 中自动运行,不再需要手动触发,所以去掉了。
- 这也是开发中的常见节奏:**先手动测试 → 确认 OK → 集成到自动化流程**。
#### 5. 当前完整流程图
```
Update()
├── HandleInput() → 读取 A/D/K 输入
├── HandleMovement() → xInput → velocity
├── HandleAnimations() → velocity.x != 0 → 跑/停 动画
└── HandleFlip() → 方向不一致时 Flip()
└── Flip()
├── Rotate(0, 180, 0)
└── facingRight = !facingRight
```
---
## 2026-05-25 · 第九次更新
**文件:** `Assets/Player.cs`
```csharp
using Unity.VisualScripting;
using UnityEngine;
public class Player : MonoBehaviour
{
private Animator anim;
private Rigidbody2D rb;
[Header("Movement details")]
[SerializeField] private float moveSpeed = 4.58f;
[SerializeField] private float jumpForce = 12;
private bool facingRight = true;
private float xInput;
[Header("Collision details")]
[SerializeField] private float groundCheckDistance;
[SerializeField] private LayerMask whatIsGround;
private bool isGrounded;
// ... Awake 同上 ...
private void Update()
{
HandleCollision(); // ← 新增,放在最前面
HandleInput();
HandleMovement();
HandleAnimations();
HandleFlip();
}
// ... HandleInput、HandleMovement、HandleAnimations、HandleFlip、Flip 同上 ...
private void jump()
{
if(isGrounded) // ← 加了接地判断
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
}
private void HandleCollision()
{
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundCheckDistance, whatIsGround);
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(transform.position, transform.position + new Vector3(0, -groundCheckDistance));
}
}
```
### 本次改动 · 新增知识点
#### 1. 地面检测 (`isGrounded`) 解决无限跳跃
- 之前跳跃没有限制,空中也能一直跳。
- 现在 `jump()` 加了 `if(isGrounded)` 判断,只有站在地面上才能跳。
#### 2. `Physics2D.Raycast()` —— 2D 射线检测
- 从指定位置向指定方向发射一条**不可见的射线**,检测是否碰到碰撞体。
- 参数:`Physics2D.Raycast(起点, 方向, 距离, 层级掩码)`
- 当前用法:
```
起点transform.position角色脚底位置
方向Vector2.down向下
距离groundCheckDistance
过滤whatIsGround只检测地面层
```
```
角色
─────┼───── transform.position
↓ 射线 (Vector2.down, 长度 = groundCheckDistance)
═════╪═════ 地面碰撞体 → 射线命中 → isGrounded = true
······│······ 没碰到地面 → isGrounded = false在空中
```
#### 3. `[Header("...")]` —— Inspector 分组标签
- Unity 会把 Inspector 字段按 `[Header]` 分组,加上加粗标题。
- 让 Inspector 面板更有条理:
```
┌─ Player (Script) ──────────────┐
│ Script Player │
│ │
│ ── Movement details ── │ ← [Header("Movement details")]
│ Move Speed 4.58 │
│ Jump Force 12 │
│ │
│ ── Collision details ── │ ← [Header("Collision details")]
│ Ground Check Distance 1.5 │
│ What Is Ground Ground ▾ │
└────────────────────────────────┘
```
#### 4. `LayerMask` —— 层级过滤
- `LayerMask whatIsGround` 在 Inspector 中显示为下拉菜单,可以选择哪些 Layer 算作"地面"。
- 射线只会检测被选中的层,忽略其他层(玩家自身、敌人等)。
- **必须设置:** 给地面物体分配一个 Layer如"Ground"),然后在 Player 的 `whatIsGround` 中勾选它。
#### 5. `OnDrawGizmos()` —— Scene 视图可视化调试
- `Gizmos.DrawLine(起点, 终点)` 在 Scene 视图中画线,方便调试射线位置。
- 只在编辑器 Scene 视图可见,游戏运行时不会显示。
- 当前画了一条向下的红线,直观看到 `groundCheckDistance` 的长度是否合适。
#### 6. ⚠️ 注意事项
- `using Unity.VisualScripting;` 是多余的引用,当前代码并未使用 Visual Scripting 功能。可以安全删除,不影响编译但保持代码整洁。
- `jump()` 中 `if(isGrounded)` 后面没有花括号 —— 只有一行代码时可以省略 `{}`,但建议养成始终加括号的习惯,避免后续扩展时出错。
#### 7. `Vector2.down` 快捷向量
| 写法 | 等价于 | 含义 |
|---|---|---|
| `Vector2.up` | `(0, 1)` | 上 |
| `Vector2.down` | `(0, -1)` | 下 |
| `Vector2.left` | `(-1, 0)` | 左 |
| `Vector2.right` | `(1, 0)` | 右 |
| `Vector2.zero` | `(0, 0)` | 零向量 |
| `Vector2.one` | `(1, 1)` | 单位向量 |
#### 8. 当前架构图(更新版)
```
Player (MonoBehaviour)
├── Awake()
│ ├── rb = GetComponent<Rigidbody2D>()
│ └── anim = GetComponentInChildren<Animator>()
├── Update()
│ ├── HandleCollision() → Raycast 向下 → isGrounded
│ ├── HandleInput() → 读取按键
│ ├── HandleMovement() → 设置 velocity
│ ├── HandleAnimations() → 驱动动画
│ └── HandleFlip() → 自动转向
└── OnDrawGizmos() → Scene 视图画射线(仅编辑器)
```