检测
This commit is contained in:
parent
a15a5c22c3
commit
c62fb62968
@ -312,7 +312,7 @@ GameObject:
|
|||||||
- component: {fileID: 700694697}
|
- component: {fileID: 700694697}
|
||||||
- component: {fileID: 700694696}
|
- component: {fileID: 700694696}
|
||||||
- component: {fileID: 700694695}
|
- component: {fileID: 700694695}
|
||||||
m_Layer: 0
|
m_Layer: 6
|
||||||
m_Name: Middle
|
m_Name: Middle
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
@ -2466,6 +2466,7 @@ GameObject:
|
|||||||
- component: {fileID: 887481107}
|
- component: {fileID: 887481107}
|
||||||
- component: {fileID: 887481106}
|
- component: {fileID: 887481106}
|
||||||
- component: {fileID: 887481108}
|
- component: {fileID: 887481108}
|
||||||
|
- component: {fileID: 887481109}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Player
|
m_Name: Player
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -2549,7 +2550,7 @@ CapsuleCollider2D:
|
|||||||
m_GameObject: {fileID: 887481103}
|
m_GameObject: {fileID: 887481103}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_Density: 1
|
m_Density: 1
|
||||||
m_Material: {fileID: 0}
|
m_Material: {fileID: 6200000, guid: 9930d3d9bf689d84fbbbc53b8eb3db02, type: 2}
|
||||||
m_IncludeLayers:
|
m_IncludeLayers:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 0
|
m_Bits: 0
|
||||||
@ -2617,6 +2618,24 @@ MonoBehaviour:
|
|||||||
inputDirection: {x: 0, y: 0}
|
inputDirection: {x: 0, y: 0}
|
||||||
speed: 300
|
speed: 300
|
||||||
jumpForce: 17
|
jumpForce: 17
|
||||||
|
--- !u!114 &887481109
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 887481103}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 4ac0f40285681b74c841e22ebbe583d5, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
bottomOffest: {x: -0.07, y: 0}
|
||||||
|
checkRaduis: 0.06
|
||||||
|
groundLayer:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 64
|
||||||
|
isGround: 0
|
||||||
--- !u!1 &1021266681
|
--- !u!1 &1021266681
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -3538,7 +3557,7 @@ Tilemap:
|
|||||||
- {fileID: 1961145818, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1961145818, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: 1737103796, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1737103796, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: -23635172, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: -23635172, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
m_AnimationSpeed: 7
|
m_AnimationSpeed: 7.0000005
|
||||||
m_AnimationTimeOffset: 0
|
m_AnimationTimeOffset: 0
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
- first: {x: 5, y: 4, z: 0}
|
- first: {x: 5, y: 4, z: 0}
|
||||||
@ -3582,7 +3601,7 @@ Tilemap:
|
|||||||
- {fileID: 1051226569, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1051226569, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: 1588357252, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1588357252, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: -1843162688, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: -1843162688, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
m_AnimationSpeed: 7.0000005
|
m_AnimationSpeed: 7
|
||||||
m_AnimationTimeOffset: 0
|
m_AnimationTimeOffset: 0
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
- first: {x: 6, y: 5, z: 0}
|
- first: {x: 6, y: 5, z: 0}
|
||||||
@ -3791,7 +3810,7 @@ Tilemap:
|
|||||||
- {fileID: 1369434452, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1369434452, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: -714309378, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: -714309378, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: -1306249692, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: -1306249692, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
m_AnimationSpeed: 7
|
m_AnimationSpeed: 7.0000005
|
||||||
m_AnimationTimeOffset: 0
|
m_AnimationTimeOffset: 0
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
- first: {x: 7, y: 11, z: 0}
|
- first: {x: 7, y: 11, z: 0}
|
||||||
@ -3813,7 +3832,7 @@ Tilemap:
|
|||||||
- {fileID: 1051226569, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1051226569, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: 1588357252, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1588357252, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: -1843162688, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: -1843162688, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
m_AnimationSpeed: 7.0000005
|
m_AnimationSpeed: 7
|
||||||
m_AnimationTimeOffset: 0
|
m_AnimationTimeOffset: 0
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
- first: {x: 6, y: 12, z: 0}
|
- first: {x: 6, y: 12, z: 0}
|
||||||
@ -3879,7 +3898,7 @@ Tilemap:
|
|||||||
- {fileID: 1051226569, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1051226569, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: 1588357252, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: 1588357252, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
- {fileID: -1843162688, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
- {fileID: -1843162688, guid: d4dcc96007437b741bd8f3a3c7e02b45, type: 3}
|
||||||
m_AnimationSpeed: 7.0000005
|
m_AnimationSpeed: 7
|
||||||
m_AnimationTimeOffset: 0
|
m_AnimationTimeOffset: 0
|
||||||
m_Flags: 0
|
m_Flags: 0
|
||||||
- first: {x: 6, y: 14, z: 0}
|
- first: {x: 6, y: 14, z: 0}
|
||||||
|
32
Assets/Scripts/Player/PhysicsCheck.cs
Normal file
32
Assets/Scripts/Player/PhysicsCheck.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class PhysicsCheck : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("¼ì²â²ÎÊý")]
|
||||||
|
public Vector2 bottomOffest;
|
||||||
|
|
||||||
|
public float checkRaduis;
|
||||||
|
|
||||||
|
public LayerMask groundLayer;
|
||||||
|
|
||||||
|
[Header("״̬")]
|
||||||
|
public bool isGround;
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
Check();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Check()
|
||||||
|
{
|
||||||
|
isGround = Physics2D.OverlapCircle((Vector2)transform.position+bottomOffest, checkRaduis, groundLayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDrawGizmosSelected()
|
||||||
|
{
|
||||||
|
Gizmos.DrawWireSphere((Vector2)transform.position + bottomOffest, checkRaduis);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
Assets/Scripts/Player/PhysicsCheck.cs.meta
Normal file
11
Assets/Scripts/Player/PhysicsCheck.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4ac0f40285681b74c841e22ebbe583d5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -10,6 +10,7 @@ public class PlayerController : MonoBehaviour
|
|||||||
public Vector2 inputDirection;
|
public Vector2 inputDirection;
|
||||||
|
|
||||||
private Rigidbody2D rb;
|
private Rigidbody2D rb;
|
||||||
|
private PhysicsCheck physicsCheck;
|
||||||
|
|
||||||
[Header("基本参数")]
|
[Header("基本参数")]
|
||||||
public float speed;
|
public float speed;
|
||||||
@ -19,6 +20,7 @@ public class PlayerController : MonoBehaviour
|
|||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
rb = GetComponent<Rigidbody2D>();
|
rb = GetComponent<Rigidbody2D>();
|
||||||
|
physicsCheck = GetComponent<PhysicsCheck>();
|
||||||
inputControl = new PlayerInputControl();
|
inputControl = new PlayerInputControl();
|
||||||
inputControl.GamePlayerInput.Jump.started += Jump;
|
inputControl.GamePlayerInput.Jump.started += Jump;
|
||||||
|
|
||||||
@ -74,7 +76,11 @@ public class PlayerController : MonoBehaviour
|
|||||||
//跳跃
|
//跳跃
|
||||||
private void Jump(InputAction.CallbackContext context)
|
private void Jump(InputAction.CallbackContext context)
|
||||||
{
|
{
|
||||||
rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
|
if(physicsCheck.isGround)
|
||||||
|
{
|
||||||
|
rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
Assets/Settings/PhyiscsMaterials.meta
Normal file
8
Assets/Settings/PhyiscsMaterials.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 00badfeede830724ab5c052647fd99b4
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
11
Assets/Settings/PhyiscsMaterials/Normal.physicsMaterial2D
Normal file
11
Assets/Settings/PhyiscsMaterials/Normal.physicsMaterial2D
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!62 &6200000
|
||||||
|
PhysicsMaterial2D:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_Name: Normal
|
||||||
|
friction: 0
|
||||||
|
bounciness: 0
|
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9930d3d9bf689d84fbbbc53b8eb3db02
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 6200000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -11,7 +11,7 @@ TagManager:
|
|||||||
-
|
-
|
||||||
- Water
|
- Water
|
||||||
- UI
|
- UI
|
||||||
-
|
- Ground
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
-
|
-
|
||||||
|
Loading…
x
Reference in New Issue
Block a user