Batman
This commit is contained in:
13
Assets/Player/BasicCharacter.cs
Normal file
13
Assets/Player/BasicCharacter.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BasicCharacter : MonoBehaviour
|
||||
{
|
||||
protected MovementBehaviour _movementBehaviour;
|
||||
// Start is called before the first frame update
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_movementBehaviour = GetComponent<MovementBehaviour>();
|
||||
}
|
||||
}
|
||||
11
Assets/Player/BasicCharacter.cs.meta
Normal file
11
Assets/Player/BasicCharacter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a163eba71eaba34b90499cf3193f6dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
27
Assets/Player/MovementBehaviour.cs
Normal file
27
Assets/Player/MovementBehaviour.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MovementBehaviour : MonoBehaviour {
|
||||
[SerializeField]
|
||||
private float _movementSpeed = 1.0f;
|
||||
private Vector3 _desiredMovementDirection = Vector3.zero;
|
||||
public Vector3 DesiredMovementDirection
|
||||
{
|
||||
get => _desiredMovementDirection;
|
||||
set => _desiredMovementDirection = value;
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
HandleMovement();
|
||||
}
|
||||
private void HandleMovement()
|
||||
{
|
||||
Vector3 movement = _desiredMovementDirection.normalized;
|
||||
movement *= _movementSpeed;
|
||||
transform.position += movement;
|
||||
}
|
||||
public void Jump()
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Assets/Player/MovementBehaviour.cs.meta
Normal file
11
Assets/Player/MovementBehaviour.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1288b016e639a5d4c93ce7197868a196
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Assets/Player/PlayerController.cs
Normal file
39
Assets/Player/PlayerController.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class PlayerController : BasicCharacter {
|
||||
|
||||
[SerializeField] private InputActionAsset _inputAsset;
|
||||
[SerializeField] private InputActionReference _movementAction;
|
||||
|
||||
protected override void Awake() {
|
||||
base.Awake();
|
||||
if (_inputAsset == null) return;
|
||||
}
|
||||
|
||||
private void OnEnable() {
|
||||
if (_inputAsset == null) return;
|
||||
_inputAsset.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
if (_inputAsset == null) return;
|
||||
_inputAsset.Disable();
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
HandleMovementInput();
|
||||
}
|
||||
|
||||
void HandleMovementInput() {
|
||||
if (_movementBehaviour == null ||
|
||||
_movementAction == null)
|
||||
return;
|
||||
//movement
|
||||
float movementInput = _movementAction.action.ReadValue<float>();
|
||||
Vector3 movement = movementInput * Vector3.right;
|
||||
_movementBehaviour.DesiredMovementDirection = movement;
|
||||
}
|
||||
}
|
||||
11
Assets/Player/PlayerController.cs.meta
Normal file
11
Assets/Player/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 757602dc557f18440892f635a083b135
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Player/PlayerInputActions.inputactions
Normal file
89
Assets/Player/PlayerInputActions.inputactions
Normal file
@@ -0,0 +1,89 @@
|
||||
{
|
||||
"name": "PlayerInputActions",
|
||||
"maps": [
|
||||
{
|
||||
"name": "Main",
|
||||
"id": "7b37900d-cd4e-4c27-90f3-c06af4505fb8",
|
||||
"actions": [
|
||||
{
|
||||
"name": "Movement",
|
||||
"type": "PassThrough",
|
||||
"id": "b6d068d7-d5e7-41b3-ae71-885fca319d8e",
|
||||
"expectedControlType": "Vector2",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
{
|
||||
"name": "",
|
||||
"id": "a72dfc99-2883-4ee9-858b-ab9b3f86fe04",
|
||||
"path": "",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "WASD",
|
||||
"id": "76d91a25-e6c1-4124-8dba-205d06c74e49",
|
||||
"path": "2DVector",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "up",
|
||||
"id": "29851878-2ace-42a8-ab6b-fc2f88ce376d",
|
||||
"path": "<Keyboard>/w",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "down",
|
||||
"id": "f3d2d451-355c-4b22-8e89-284a4d0b499b",
|
||||
"path": "<Keyboard>/s",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "left",
|
||||
"id": "4a5878ef-f63f-4485-b599-bb524ae5fb53",
|
||||
"path": "<Keyboard>/a",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "right",
|
||||
"id": "370be7dc-94cb-4558-b143-523483d39404",
|
||||
"path": "<Keyboard>/d",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Movement",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"controlSchemes": []
|
||||
}
|
||||
14
Assets/Player/PlayerInputActions.inputactions.meta
Normal file
14
Assets/Player/PlayerInputActions.inputactions.meta
Normal file
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f54988b006d41d4eb3eb26ae11f51f9
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||
generateWrapperCode: 0
|
||||
wrapperCodePath:
|
||||
wrapperClassName:
|
||||
wrapperCodeNamespace:
|
||||
Reference in New Issue
Block a user