Added quick joystick to move + scriptableobject
This commit is contained in:
parent
18cf3b7870
commit
edea89cc59
@ -12,6 +12,8 @@ GameObject:
|
|||||||
- component: {fileID: 1214567908930553595}
|
- component: {fileID: 1214567908930553595}
|
||||||
- component: {fileID: 1214567908930553592}
|
- component: {fileID: 1214567908930553592}
|
||||||
- component: {fileID: 1214567908930553477}
|
- component: {fileID: 1214567908930553477}
|
||||||
|
- component: {fileID: 945832017}
|
||||||
|
- component: {fileID: 945832018}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Vampire
|
m_Name: Vampire
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -96,6 +98,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 639be549366b46748bd86eb6cea796a3, type: 3}
|
m_Script: {fileID: 11500000, guid: 639be549366b46748bd86eb6cea796a3, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
|
playerStats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2}
|
||||||
--- !u!114 &1214567908930553477
|
--- !u!114 &1214567908930553477
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -178,3 +181,40 @@ MonoBehaviour:
|
|||||||
m_DefaultActionMap: Player
|
m_DefaultActionMap: Player
|
||||||
m_SplitScreenIndex: -1
|
m_SplitScreenIndex: -1
|
||||||
m_Camera: {fileID: 0}
|
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
|
||||||
|
|||||||
16
Assets/Scripts/Player Stats.asset
Normal file
16
Assets/Scripts/Player Stats.asset
Normal 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
|
||||||
8
Assets/Scripts/Player Stats.asset.meta
Normal file
8
Assets/Scripts/Player Stats.asset.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 12a626b5a296d934ba078d222ad6ba98
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 11400000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -1,18 +1,34 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
public class PlayerMovement : MonoBehaviour
|
[RequireComponent(typeof(PlayerInput), typeof(Rigidbody2D))]
|
||||||
{
|
public class PlayerMovement : MonoBehaviour {
|
||||||
// Start is called before the first frame update
|
[SerializeField] PlayerStats playerStats;
|
||||||
void Start()
|
|
||||||
{
|
PlayerInput playerInput;
|
||||||
|
Vector2 moveDirection;
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
void Start() {
|
||||||
void Update()
|
playerInput = GetComponent<PlayerInput>();
|
||||||
{
|
|
||||||
|
playerInput.actions["Move"].started += OnMove;
|
||||||
}
|
playerInput.actions["Move"].performed += OnMove;
|
||||||
}
|
playerInput.actions["Move"].canceled += OnMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
7
Assets/Scripts/PlayerStats.cs
Normal file
7
Assets/Scripts/PlayerStats.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
[CreateAssetMenu]
|
||||||
|
public class PlayerStats : ScriptableObject {
|
||||||
|
public float movementSpeed = 3f;
|
||||||
|
public float suckSpeed = 1f;
|
||||||
|
}
|
||||||
3
Assets/Scripts/PlayerStats.cs.meta
Normal file
3
Assets/Scripts/PlayerStats.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5a9c2f4541a74e86afc424d568e0f629
|
||||||
|
timeCreated: 1648869672
|
||||||
Loading…
x
Reference in New Issue
Block a user