playing with input, updated to 20.1.14
This commit is contained in:
parent
9254c5bfff
commit
a12f23edc8
@ -9,90 +9,90 @@ AnimatorController:
|
||||
m_Name: HeroKnight_AnimController
|
||||
serializedVersion: 5
|
||||
m_AnimatorParameters:
|
||||
- m_Name: AnimState
|
||||
m_Type: 3
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: Attack1
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Attack2
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Attack3
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Block
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: IdleBlock
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Hurt
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Death
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: noBlood
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: AirSpeedY
|
||||
m_Type: 1
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Grounded
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Jump
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Roll
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: WallSlide
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: velocityX
|
||||
m_Type: 1
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
@ -189,9 +189,9 @@ AnimatorStateTransition:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 7
|
||||
m_ConditionEvent: AnimState
|
||||
m_EventTreshold: 1
|
||||
- m_ConditionMode: 4
|
||||
m_ConditionEvent: velocityX
|
||||
m_EventTreshold: 0.01
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 110215012}
|
||||
m_Solo: 0
|
||||
@ -214,9 +214,9 @@ AnimatorStateTransition:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 6
|
||||
m_ConditionEvent: AnimState
|
||||
m_EventTreshold: 1
|
||||
- m_ConditionMode: 3
|
||||
m_ConditionEvent: velocityX
|
||||
m_EventTreshold: 0.01
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: Grounded
|
||||
m_EventTreshold: 0
|
||||
|
@ -7,5 +7,5 @@ PhysicsMaterial2D:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Slippery
|
||||
friction: 0
|
||||
friction: 2.03
|
||||
bounciness: 0
|
||||
|
@ -9,8 +9,8 @@ GameObject:
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1127540733912009899}
|
||||
- component: {fileID: 1127540733912009872}
|
||||
- component: {fileID: 1127540733912009878}
|
||||
- component: {fileID: 3491593317981466529}
|
||||
- component: {fileID: 6797072187872310423}
|
||||
- component: {fileID: 1127540733912009879}
|
||||
- component: {fileID: 1127540733912009898}
|
||||
- component: {fileID: 1127540733912009897}
|
||||
@ -32,13 +32,40 @@ Transform:
|
||||
m_GameObject: {fileID: 1127540733912009896}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 1.715, y: -0.997, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_LocalScale: {x: 0.5, y: 0.5, z: 1}
|
||||
m_Children:
|
||||
- {fileID: 2304939454363803644}
|
||||
- {fileID: 5791193952849643086}
|
||||
- {fileID: 2500631850169134201}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1127540733912009872
|
||||
--- !u!114 &3491593317981466529
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1127540733912009896}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 93901469630e05d44b17e377c626e770, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_JumpForce: 400
|
||||
m_DoubleJumpForce: 13
|
||||
m_MovementSmoothing: 0.05
|
||||
m_AirControl: 1
|
||||
m_WhatIsGround:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_GroundCheck: {fileID: 2500631850169134201}
|
||||
m_CeilingCheck: {fileID: 5791193952849643086}
|
||||
animator: {fileID: 1127540733912009897}
|
||||
OnLandEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
--- !u!114 &6797072187872310423
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
@ -50,98 +77,13 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 1eeb02edb6a1deb74a75b45546de034e, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
animator: {fileID: 0}
|
||||
--- !u!114 &1127540733912009878
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1127540733912009896}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 62899f850307741f2a39c98a8b639597, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_Actions: {fileID: -944628639613478452, guid: 2e7f0548f4e61755da3ffa548781763d,
|
||||
type: 3}
|
||||
m_NotificationBehavior: 2
|
||||
m_UIInputModule: {fileID: 0}
|
||||
m_DeviceLostEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_DeviceRegainedEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ControlsChangedEvent:
|
||||
m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionEvents:
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: ad90ff3f-4c39-4cad-a772-7dcf47bc17d4
|
||||
m_ActionName: Player/Move[/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 37d38fed-ad25-4a1e-b364-2183f4b904ec
|
||||
m_ActionName: Player/Fire[/Mouse/leftButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 5782a88d-1841-4f28-8732-f43984baeab5
|
||||
m_ActionName: UI/Navigate[/Keyboard/w,/Keyboard/upArrow,/Keyboard/s,/Keyboard/downArrow,/Keyboard/a,/Keyboard/leftArrow,/Keyboard/d,/Keyboard/rightArrow]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 644f1157-b110-4dc6-bbd3-89bddab12ecb
|
||||
m_ActionName: UI/Submit[/Keyboard/enter]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 126194ef-8bb8-44f7-b4bf-d73a414d241b
|
||||
m_ActionName: UI/Cancel[/Keyboard/escape]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 81e334c8-3186-45e3-a7f7-655e521d0cbf
|
||||
m_ActionName: UI/Point[/Mouse/position]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 5cd558dc-0e4e-42c8-bd1e-339f618c33a9
|
||||
m_ActionName: UI/Click[/Mouse/leftButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: bdcee344-b797-424a-b13b-9711476f636f
|
||||
m_ActionName: UI/ScrollWheel[/Mouse/scroll]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: a669cd7a-e2a4-4a1c-afe4-9664a78b8e29
|
||||
m_ActionName: UI/MiddleClick[/Mouse/middleButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 954f4b8a-466a-4a50-9bfe-c8869f697714
|
||||
m_ActionName: UI/RightClick[/Mouse/rightButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: a4ca47d9-48a1-420a-92e5-ce36ecb1c664
|
||||
m_ActionName: UI/TrackedDevicePosition
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 5ad0c81e-b151-4be1-934b-489a8256fa25
|
||||
m_ActionName: UI/TrackedDeviceOrientation
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 89cb3776-bd09-436f-b835-ebf7638e6c29
|
||||
m_ActionName: Player/Jump[/Keyboard/space]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: 79db912d-931d-4cef-b244-acd0a7f14eff
|
||||
m_ActionName: Player/Block[/Mouse/rightButton]
|
||||
- m_PersistentCalls:
|
||||
m_Calls: []
|
||||
m_ActionId: a4698e98-2f8a-488e-86a2-7b47eed1ec2c
|
||||
m_ActionName: Player/Roll[/Keyboard/leftCtrl]
|
||||
m_NeverAutoSwitchControlSchemes: 0
|
||||
m_DefaultControlScheme:
|
||||
m_DefaultActionMap: Player
|
||||
m_SplitScreenIndex: -1
|
||||
m_Camera: {fileID: 0}
|
||||
controller: {fileID: 3491593317981466529}
|
||||
collider2d: {fileID: 1127540733912009876}
|
||||
animator: {fileID: 1127540733912009897}
|
||||
health: {fileID: 1127540733912009879}
|
||||
flash: {fileID: 0}
|
||||
controlAllowed: 1
|
||||
runSpeed: 40
|
||||
--- !u!114 &1127540733912009879
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -183,7 +125,7 @@ SpriteRenderer:
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2}
|
||||
- {fileID: 2100000, guid: 690f510032fea7de5804229802dd19be, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
@ -271,6 +213,66 @@ CapsuleCollider2D:
|
||||
m_Offset: {x: -0.035320938, y: 0.637541}
|
||||
m_Size: {x: 0.59497917, y: 1.262972}
|
||||
m_Direction: 0
|
||||
--- !u!1 &2402365339917271187
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5791193952849643086}
|
||||
m_Layer: 8
|
||||
m_Name: Head
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5791193952849643086
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2402365339917271187}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 1.228, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1127540733912009899}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &3756252022205983292
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 2500631850169134201}
|
||||
m_Layer: 8
|
||||
m_Name: Ground
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &2500631850169134201
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3756252022205983292}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0.056, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1127540733912009899}
|
||||
m_RootOrder: 2
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &4324413887002832254
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,46 +1,80 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Pink.Environment;
|
||||
using Pink.Graphics;
|
||||
using Pink.Events;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Experimental.Rendering.Universal;
|
||||
|
||||
public class Hero : MonoBehaviour
|
||||
using static Pink.Environment.Simulation;
|
||||
|
||||
namespace Pink.Mechanics
|
||||
{
|
||||
public Animator animator;
|
||||
[RequireComponent(typeof(CharacterKinematics))]
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(Health))]
|
||||
public class Hero : MonoBehaviour
|
||||
{
|
||||
public HeroInput input;
|
||||
public CharacterKinematics controller;
|
||||
public Collider2D collider2d;
|
||||
public Animator animator;
|
||||
public Health health;
|
||||
public Flash flash;
|
||||
|
||||
public bool controlAllowed = true;
|
||||
|
||||
[Min(0)]
|
||||
public float runSpeed = 40f;
|
||||
float horizontalMovement = 0f;
|
||||
bool jump = false;
|
||||
|
||||
private System.Random random;
|
||||
|
||||
private void OnEnable() {
|
||||
input.Enable();
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Debug.Log("Player Created");
|
||||
}
|
||||
|
||||
private void OnDisable() {
|
||||
input.Disable();
|
||||
}
|
||||
|
||||
private void Awake() {
|
||||
void Awake()
|
||||
{
|
||||
input = new HeroInput();
|
||||
random = new System.Random();
|
||||
|
||||
input.Player.Move.performed += ctx => OnMove(ctx);
|
||||
input.Player.Jump.performed += ctx => OnJump(ctx);
|
||||
input.Player.Attack.performed += ctx => OnAttack(ctx);
|
||||
input.Player.Block.performed += ctx => OnBlock(ctx);
|
||||
input.Player.Roll.performed += ctx => OnRoll(ctx);
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
input.Enable();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
input.Disable();
|
||||
}
|
||||
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
Debug.Log("Moving: " + context);
|
||||
horizontalMovement = controlAllowed ? context.ReadValue<Vector2>().x * runSpeed : 0;
|
||||
}
|
||||
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (controlAllowed)
|
||||
{
|
||||
Debug.Log("Jumping");
|
||||
animator.SetTrigger("Jump");
|
||||
jump = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
int attackNumber = random.Next(1,4);
|
||||
int attackNumber = random.Next(1, 4);
|
||||
animator.SetTrigger("Attack" + attackNumber.ToString());
|
||||
}
|
||||
|
||||
@ -55,12 +89,43 @@ public class Hero : MonoBehaviour
|
||||
animator.SetTrigger("Roll");
|
||||
}
|
||||
|
||||
private void Update() {
|
||||
Keyboard kb = InputSystem.GetDevice<Keyboard>();
|
||||
if(kb.spaceKey.wasPressedThisFrame)
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
Debug.Log("SPACE");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
controller.Move(horizontalMovement * Time.fixedDeltaTime, jump);
|
||||
jump = false;
|
||||
}
|
||||
|
||||
// Animation and graphic updates triggered primarily by health component
|
||||
public void WasHurt()
|
||||
{
|
||||
if (health.IsDead)
|
||||
{
|
||||
animator.SetTrigger("dead");
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.SetTrigger("hurt");
|
||||
}
|
||||
if (flash != null) StartCoroutine(flash.Run(3, 60, 60, 1f));
|
||||
}
|
||||
|
||||
// Animation and graphic updates triggered primarily by health component
|
||||
public void WasHealed()
|
||||
{
|
||||
animator.SetTrigger("");
|
||||
}
|
||||
|
||||
// Animation, graphic updates and death event scheduling triggered primarily by health component
|
||||
public void WasKilled()
|
||||
{
|
||||
animator.SetBool("dead", true);
|
||||
Schedule<PlayerDeath>();
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,10 @@ namespace Pink.Mechanics
|
||||
/// </summary>
|
||||
public float jumpTakeOffSpeed = 7;
|
||||
|
||||
public Animator animator;
|
||||
public HeroInput input;
|
||||
private System.Random random;
|
||||
|
||||
public JumpState jumpState = JumpState.Grounded;
|
||||
private bool stopJump;
|
||||
/*internal new*/
|
||||
@ -26,7 +30,6 @@ namespace Pink.Mechanics
|
||||
bool jump;
|
||||
Vector2 move;
|
||||
SpriteRenderer spriteRenderer;
|
||||
internal Animator animator;
|
||||
|
||||
public Bounds Bounds => collider2d.bounds;
|
||||
|
||||
@ -37,25 +40,86 @@ namespace Pink.Mechanics
|
||||
collider2d = GetComponent<Collider2D>();
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
animator = GetComponent<Animator>();
|
||||
|
||||
input = new HeroInput();
|
||||
random = new System.Random();
|
||||
|
||||
input.Player.Move.performed += ctx => OnMove(ctx);
|
||||
input.Player.Jump.performed += ctx => OnJump(ctx);
|
||||
input.Player.Attack.performed += ctx => OnAttack(ctx);
|
||||
input.Player.Block.performed += ctx => OnBlock(ctx);
|
||||
input.Player.Roll.performed += ctx => OnRoll(ctx);
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
input.Enable();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected override void Update()
|
||||
private void OnDisable()
|
||||
{
|
||||
input.Disable();
|
||||
}
|
||||
|
||||
public void OnMove(InputAction.CallbackContext context)
|
||||
{
|
||||
if (controlEnabled)
|
||||
{
|
||||
move.x = Input.GetAxis("Horizontal");
|
||||
if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump"))
|
||||
jumpState = JumpState.PrepareToJump;
|
||||
else if (Input.GetButtonUp("Jump"))
|
||||
{
|
||||
stopJump = true;
|
||||
}
|
||||
move.x = context.ReadValue<Vector2>().x;
|
||||
animator.SetFloat("", move.x);
|
||||
Debug.Log("Moving: " + move.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
move.x = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnJump(InputAction.CallbackContext context)
|
||||
{
|
||||
if (jumpState == JumpState.Grounded)
|
||||
jumpState = JumpState.PrepareToJump;
|
||||
|
||||
// stopJump = true; on up
|
||||
|
||||
Debug.Log("Jumping");
|
||||
animator.SetTrigger("Jump");
|
||||
}
|
||||
|
||||
public void OnAttack(InputAction.CallbackContext context)
|
||||
{
|
||||
int attackNumber = random.Next(1, 4);
|
||||
animator.SetTrigger("Attack" + attackNumber.ToString());
|
||||
}
|
||||
|
||||
public void OnBlock(InputAction.CallbackContext context)
|
||||
{
|
||||
animator.SetTrigger("Block");
|
||||
}
|
||||
|
||||
public void OnRoll(InputAction.CallbackContext context)
|
||||
{
|
||||
Debug.Log("Rolling");
|
||||
animator.SetTrigger("Roll");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected override void Update()
|
||||
{
|
||||
//if (controlEnabled)
|
||||
//{
|
||||
// move.x = Input.GetAxis("Horizontal");
|
||||
// if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump"))
|
||||
// jumpState = JumpState.PrepareToJump;
|
||||
// else if (Input.GetButtonUp("Jump"))
|
||||
// {
|
||||
// stopJump = true;
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// move.x = 0;
|
||||
//}
|
||||
UpdateJumpState();
|
||||
base.Update();
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace Pink.Mechanics
|
||||
/// <summary>
|
||||
/// The current velocity of the entity.
|
||||
/// </summary>
|
||||
[HideInInspector]
|
||||
public Vector2 velocity;
|
||||
|
||||
/// <summary>
|
||||
@ -32,7 +33,7 @@ namespace Pink.Mechanics
|
||||
|
||||
protected Vector2 targetVelocity;
|
||||
protected Vector2 groundNormal;
|
||||
protected Rigidbody2D body;
|
||||
public Rigidbody2D body;
|
||||
protected ContactFilter2D contactFilter;
|
||||
protected RaycastHit2D[] hitBuffer = new RaycastHit2D[16];
|
||||
|
||||
@ -169,7 +170,7 @@ namespace Pink.Mechanics
|
||||
distance = modifiedDistance < distance ? modifiedDistance : distance;
|
||||
}
|
||||
}
|
||||
body.position = body.position + move.normalized * distance;
|
||||
body.position += move.normalized * distance;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.2d.animation": "4.2.5",
|
||||
"com.unity.2d.animation": "4.2.6",
|
||||
"com.unity.2d.pixel-perfect": "3.0.2",
|
||||
"com.unity.2d.psdimporter": "3.1.5",
|
||||
"com.unity.2d.psdimporter": "3.1.6",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.2d.spriteshape": "4.1.3",
|
||||
"com.unity.2d.spriteshape": "4.1.4",
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.cinemachine": "2.6.2",
|
||||
"com.unity.collab-proxy": "1.3.9",
|
||||
"com.unity.ext.nunit": "1.0.0",
|
||||
"com.unity.ide.rider": "1.2.1",
|
||||
"com.unity.ide.visualstudio": "2.0.3",
|
||||
"com.unity.ide.vscode": "1.2.2",
|
||||
"com.unity.ide.vscode": "1.2.3",
|
||||
"com.unity.inputsystem": "1.0.0",
|
||||
"com.unity.postprocessing": "2.3.0",
|
||||
"com.unity.render-pipelines.universal": "8.2.0",
|
||||
"com.unity.test-framework": "1.1.16",
|
||||
"com.unity.test-framework": "1.1.18",
|
||||
"com.unity.textmeshpro": "3.0.1",
|
||||
"com.unity.timeline": "1.3.6",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.2d.animation": {
|
||||
"version": "4.2.5",
|
||||
"version": "4.2.6",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -38,12 +38,12 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.2d.psdimporter": {
|
||||
"version": "3.1.5",
|
||||
"version": "3.1.6",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.2d.common": "3.0.1",
|
||||
"com.unity.2d.animation": "4.2.5",
|
||||
"com.unity.2d.animation": "4.2.6",
|
||||
"com.unity.2d.sprite": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.com"
|
||||
@ -55,7 +55,7 @@
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.2d.spriteshape": {
|
||||
"version": "4.1.3",
|
||||
"version": "4.1.4",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
@ -110,7 +110,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.ide.vscode": {
|
||||
"version": "1.2.2",
|
||||
"version": "1.2.3",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
@ -174,7 +174,7 @@
|
||||
"url": "https://packages.unity.com"
|
||||
},
|
||||
"com.unity.test-framework": {
|
||||
"version": "1.1.16",
|
||||
"version": "1.1.18",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
|
@ -1,2 +1,2 @@
|
||||
m_EditorVersion: 2020.1.7f1
|
||||
m_EditorVersionWithRevision: 2020.1.7f1 (064ffcdb64ad)
|
||||
m_EditorVersion: 2020.1.14f1
|
||||
m_EditorVersionWithRevision: 2020.1.14f1 (d81f64f5201d)
|
||||
|
Loading…
Reference in New Issue
Block a user