Added quick joystick to move + scriptableobject

This commit is contained in:
Jason Durand 01 2022-04-01 23:35:34 -04:00
parent 18cf3b7870
commit edea89cc59
6 changed files with 105 additions and 15 deletions

View File

@ -12,6 +12,8 @@ GameObject:
- component: {fileID: 1214567908930553595}
- component: {fileID: 1214567908930553592}
- component: {fileID: 1214567908930553477}
- component: {fileID: 945832017}
- component: {fileID: 945832018}
m_Layer: 0
m_Name: Vampire
m_TagString: Untagged
@ -96,6 +98,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 639be549366b46748bd86eb6cea796a3, type: 3}
m_Name:
m_EditorClassIdentifier:
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
--- !u!114 &1214567908930553477
MonoBehaviour:
m_ObjectHideFlags: 0
@ -178,3 +181,40 @@ MonoBehaviour:
m_DefaultActionMap: Player
m_SplitScreenIndex: -1
m_Camera: {fileID: 0}
--- !u!50 &945832017
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1214567908930553593}
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 1
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!58 &945832018
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1214567908930553593}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.5

View File

@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5a9c2f4541a74e86afc424d568e0f629, type: 3}
m_Name: Player Stats
m_EditorClassIdentifier:
movementSpeed: 3
suckSpeed: 1

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 12a626b5a296d934ba078d222ad6ba98
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,18 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
public class PlayerMovement : MonoBehaviour {
[SerializeField] PlayerStats playerStats;
PlayerInput playerInput;
Vector2 moveDirection;
void Start() {
playerInput = GetComponent<PlayerInput>();
playerInput.actions["Move"].started += OnMove;
playerInput.actions["Move"].performed += OnMove;
playerInput.actions["Move"].canceled += OnMove;
}
// Update is called once per frame
void Update()
{
void OnDestroy() {
playerInput.actions["Move"].started -= OnMove;
playerInput.actions["Move"].performed -= OnMove;
playerInput.actions["Move"].canceled -= OnMove;
}
void Update() {
transform.position += (Vector3)moveDirection * Time.deltaTime * playerStats.movementSpeed;
}
void OnMove(InputAction.CallbackContext ctx) {
moveDirection = ctx.ReadValue<Vector2>();
if (moveDirection.sqrMagnitude > 1.0f)
moveDirection.Normalize();
}
}

View File

@ -0,0 +1,7 @@
using UnityEngine;
[CreateAssetMenu]
public class PlayerStats : ScriptableObject {
public float movementSpeed = 3f;
public float suckSpeed = 1f;
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5a9c2f4541a74e86afc424d568e0f629
timeCreated: 1648869672