Skip to content

Commit

Permalink
Added Player Walk Animations + Animation Handler Script
Browse files Browse the repository at this point in the history
I made so walk and idle sprites and made the player play the walk animations when the corresponding button is pressed.
  • Loading branch information
Fxll3n committed Jan 6, 2024
1 parent db28146 commit 4743ed2
Show file tree
Hide file tree
Showing 26 changed files with 2,165 additions and 24 deletions.
45 changes: 40 additions & 5 deletions Assets/Scenes/TestingMap.unity
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ GameObject:
- component: {fileID: 155176397}
- component: {fileID: 155176396}
- component: {fileID: 155176395}
- component: {fileID: 155176398}
- component: {fileID: 155176399}
m_Layer: 0
m_Name: Player
m_TagString: Player
Expand Down Expand Up @@ -196,12 +198,12 @@ SpriteRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 3
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 0, g: 1, b: 0.87130284, a: 1}
m_Sprite: {fileID: 1757209178, guid: eb7899fb08c1e3c439da14c7dc484ee0, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_Size: {x: 2, y: 2}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
Expand All @@ -223,6 +225,39 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!95 &155176398
Animator:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 155176394}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 99c1aa613ffe97d45922421055d465a4, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!114 &155176399
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 155176394}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d7c4acc442139f040bb27adb9700275e, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &178798824
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -260,7 +295,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -39.299927, y: 2.2999878}
m_AnchoredPosition: {x: -39.299927, y: 0}
m_SizeDelta: {x: 250, y: 70}
m_Pivot: {x: 1, y: 0}
--- !u!114 &178798826
Expand Down Expand Up @@ -595,7 +630,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 5
orthographic size: 2.9481711
m_Depth: -1
m_CullingMask:
serializedVersion: 2
Expand Down
31 changes: 13 additions & 18 deletions Assets/Scripts/Grid Movement.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GridMovement : MonoBehaviour
{
public float gridSize = 1f; // Adjust this to your grid size
public float moveSpeed = 5f; // Adjust this to your desired movement speed
public float gridSize = 1f;
public float moveSpeed = 5f;

private Vector3 targetPosition;
private bool isMoving = false;

Expand All @@ -18,21 +17,12 @@ private void Update()
{
if (!isMoving)
{
if (Input.GetKey(KeyCode.UpArrow))
{
Move(Vector3.up);
}
else if (Input.GetKey(KeyCode.DownArrow))
{
Move(Vector3.down);
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
Move(Vector3.left);
}
else if (Input.GetKey(KeyCode.RightArrow))
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

if (Mathf.Abs(horizontalInput) > 0.1f || Mathf.Abs(verticalInput) > 0.1f)
{
Move(Vector3.right);
Move(new Vector3(horizontalInput, verticalInput, 0f));
}
}
}
Expand All @@ -55,4 +45,9 @@ private void FixedUpdate()
}
}
}

public bool IsMoving()
{
return isMoving;
}
}
26 changes: 26 additions & 0 deletions Assets/Scripts/PlayerAnimator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;

public class PlayerAnimator : MonoBehaviour
{
private Animator animator;

private void Start()
{
animator = GetComponent<Animator>();
}

private void Update()
{
UpdateAnimator();
}

private void UpdateAnimator()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

animator.SetFloat("Horizontal", horizontalInput);
animator.SetFloat("Vertical", verticalInput);
animator.SetBool("IsMoving", GetComponent<GridMovement>().IsMoving());
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/PlayerAnimator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Sprites/playerOneCharacterSheet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4743ed2

Please sign in to comment.