This commit is contained in:
haitem 2021-01-29 23:00:16 +01:00
parent 63e2927e83
commit 761861e135
5 changed files with 177 additions and 51 deletions

50
Assets/Prefab/PPV.prefab Normal file
View File

@ -0,0 +1,50 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7152489397314124950
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7152489397314124952}
- component: {fileID: 7152489397314124953}
m_Layer: 8
m_Name: PPV
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7152489397314124952
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7152489397314124950}
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_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &7152489397314124953
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7152489397314124950}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3}
m_Name:
m_EditorClassIdentifier:
sharedProfile: {fileID: 11400000, guid: 45c620574ff0f6043888e8f692caf52b, type: 2}
isGlobal: 1
blendDistance: 0
weight: 1
priority: 0

View File

@ -176,6 +176,7 @@ GameObject:
- component: {fileID: 8667386836911801601} - component: {fileID: 8667386836911801601}
- component: {fileID: 8667386836911801600} - component: {fileID: 8667386836911801600}
- component: {fileID: 8667386836911801603} - component: {fileID: 8667386836911801603}
- component: {fileID: 4768974422273388731}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
m_TagString: Player m_TagString: Player
@ -246,6 +247,22 @@ MonoBehaviour:
runSpeed: 20 runSpeed: 20
rotateSpeed: 5 rotateSpeed: 5
mouseSensitive: 100 mouseSensitive: 100
jump: 5
onGround: 0
--- !u!136 &4768974422273388731
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8667386836911801605}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
m_Radius: 0.35
m_Height: 2
m_Direction: 1
m_Center: {x: 0, y: 0.9, z: 0}
--- !u!1 &8667386838808186343 --- !u!1 &8667386838808186343
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -135,7 +135,7 @@ GameObject:
- component: {fileID: 763829263} - component: {fileID: 763829263}
m_Layer: 0 m_Layer: 0
m_Name: Cube m_Name: Cube
m_TagString: Untagged m_TagString: Ground
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@ -368,6 +368,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8667386836911801603, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
type: 3}
propertyPath: jump
value: 5
objectReference: {fileID: 0}
- target: {fileID: 8667386836911801605, guid: 4f1a4eb0e633f7740b9c4928cf54ce35, - target: {fileID: 8667386836911801605, guid: 4f1a4eb0e633f7740b9c4928cf54ce35,
type: 3} type: 3}
propertyPath: m_Name propertyPath: m_Name
@ -375,51 +380,72 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 4f1a4eb0e633f7740b9c4928cf54ce35, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 4f1a4eb0e633f7740b9c4928cf54ce35, type: 3}
--- !u!1 &1623431975 --- !u!1001 &7152489398920308657
GameObject: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} serializedVersion: 2
m_PrefabInstance: {fileID: 0} m_Modification:
m_PrefabAsset: {fileID: 0} m_TransformParent: {fileID: 0}
serializedVersion: 6 m_Modifications:
m_Component: - target: {fileID: 7152489397314124950, guid: b3358042f02e73e408eb7939bcbda893,
- component: {fileID: 1623431977} type: 3}
- component: {fileID: 1623431976} propertyPath: m_Name
m_Layer: 8 value: PPV
m_Name: PPV objectReference: {fileID: 0}
m_TagString: Untagged - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
m_Icon: {fileID: 0} type: 3}
m_NavMeshLayer: 0 propertyPath: m_RootOrder
m_StaticEditorFlags: 0 value: 3
m_IsActive: 1 objectReference: {fileID: 0}
--- !u!114 &1623431976 - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
MonoBehaviour: type: 3}
m_ObjectHideFlags: 0 propertyPath: m_LocalPosition.x
m_CorrespondingSourceObject: {fileID: 0} value: 0
m_PrefabInstance: {fileID: 0} objectReference: {fileID: 0}
m_PrefabAsset: {fileID: 0} - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
m_GameObject: {fileID: 1623431975} type: 3}
m_Enabled: 1 propertyPath: m_LocalPosition.y
m_EditorHideFlags: 0 value: 0
m_Script: {fileID: 11500000, guid: 8b9a305e18de0c04dbd257a21cd47087, type: 3} objectReference: {fileID: 0}
m_Name: - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
m_EditorClassIdentifier: type: 3}
sharedProfile: {fileID: 11400000, guid: 45c620574ff0f6043888e8f692caf52b, type: 2} propertyPath: m_LocalPosition.z
isGlobal: 1 value: 0
blendDistance: 0 objectReference: {fileID: 0}
weight: 1 - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
priority: 0 type: 3}
--- !u!4 &1623431977 propertyPath: m_LocalRotation.w
Transform: value: 1
m_ObjectHideFlags: 0 objectReference: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0} - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
m_PrefabInstance: {fileID: 0} type: 3}
m_PrefabAsset: {fileID: 0} propertyPath: m_LocalRotation.x
m_GameObject: {fileID: 1623431975} value: 0
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} objectReference: {fileID: 0}
m_LocalPosition: {x: 0, y: 0, z: 0} - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
m_LocalScale: {x: 1, y: 1, z: 1} type: 3}
m_Children: [] propertyPath: m_LocalRotation.y
m_Father: {fileID: 0} value: 0
m_RootOrder: 3 objectReference: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7152489397314124952, guid: b3358042f02e73e408eb7939bcbda893,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b3358042f02e73e408eb7939bcbda893, type: 3}

View File

@ -9,6 +9,9 @@ public class PlayerManager : MonoBehaviour
public float runSpeed = 20; public float runSpeed = 20;
public float rotateSpeed = 5; public float rotateSpeed = 5;
public float mouseSensitive = 100; public float mouseSensitive = 100;
public float jump = 5;
private Vector3 jumpPower = new Vector3();
public bool onGround = false;
private bool run = false; private bool run = false;
private Camera playerCamera; private Camera playerCamera;
private Rigidbody rigidBody; private Rigidbody rigidBody;
@ -27,7 +30,7 @@ public class PlayerManager : MonoBehaviour
{ {
Application.Quit(0); Application.Quit(0);
} }
Jump();
Move(); Move();
RunSwitch(); RunSwitch();
} }
@ -54,10 +57,22 @@ public class PlayerManager : MonoBehaviour
rigidBody.MovePosition( rigidBody.MovePosition(
transform.position + transform.position +
(transform.forward * (run ? runSpeed : speed) * Input.GetAxis("Vertical") * Time.deltaTime) + (transform.forward * (run ? runSpeed : speed) * Input.GetAxis("Vertical") * Time.deltaTime) +
(transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime) (transform.right * (run ? runSpeed : speed) * Input.GetAxis("Horizontal") * Time.deltaTime) +
jumpPower
); );
} }
void Jump()
{
Debug.Log(rigidBody.velocity.y);
if (Input.GetAxisRaw("Jump") > 0) {
if (rigidBody.velocity.y <= 2 && onGround)
{
jumpPower = transform.up * jump * Time.deltaTime;
}
}
}
void Rotate() void Rotate()
{ {
rigidBody.freezeRotation = false; rigidBody.freezeRotation = false;
@ -95,4 +110,21 @@ public class PlayerManager : MonoBehaviour
} }
rigidBody.freezeRotation = true; rigidBody.freezeRotation = true;
} }
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Ground")
{
jumpPower = Vector3.zero;
onGround = true;
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == "Ground")
{
onGround = false;
}
}
} }

View File

@ -3,7 +3,8 @@
--- !u!78 &1 --- !u!78 &1
TagManager: TagManager:
serializedVersion: 2 serializedVersion: 2
tags: [] tags:
- Ground
layers: layers:
- Default - Default
- TransparentFX - TransparentFX