Added sprite flipping by movement script

This commit is contained in:
BOT Alex 2024-02-03 21:44:51 +01:00
parent 3ad9042702
commit b2da2e48b3
5 changed files with 66 additions and 18 deletions

View File

@ -189,6 +189,7 @@ GameObject:
- component: {fileID: 3878447480781341932}
- component: {fileID: 1749848915408613053}
- component: {fileID: 1949941092232239315}
- component: {fileID: 5302021185317648001}
m_Layer: 7
m_Name: Player1
m_TagString: Player
@ -341,3 +342,16 @@ MonoBehaviour:
movement: {x: 0, y: 0}
look: {x: 0, y: 0}
whipAttack: 0
useArrowKeys: 0
--- !u!114 &5302021185317648001
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3120938410244321186}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c66441ada081b6c4c841000e83cc2b7a, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -189,6 +189,7 @@ GameObject:
- component: {fileID: 3878447480781341932}
- component: {fileID: 7071433868121438663}
- component: {fileID: 1949941092232239315}
- component: {fileID: 4751086095402136128}
m_Layer: 7
m_Name: Player2
m_TagString: Player
@ -341,3 +342,16 @@ MonoBehaviour:
movement: {x: 0, y: 0}
look: {x: 0, y: 0}
whipAttack: 0
useArrowKeys: 0
--- !u!114 &4751086095402136128
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3120938410244321186}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c66441ada081b6c4c841000e83cc2b7a, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -5,30 +5,12 @@ using UnityEngine;
public class PlayerAnimationHandler : MonoBehaviour
{
Animator animator;
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
animator = GetComponentInChildren<Animator>();
sp = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if ((transform.position - prevPos).x > 0.1f)
{
sp.flipX = false;
}
else if ((transform.position - prevPos).x < -0.1f)
{
sp.flipX = true;
}
prevPos = transform.position;
}
public void Idle()
{
animator.SetTrigger("Idle");

View File

@ -0,0 +1,27 @@
using UnityEngine;
public class SpriteMovementFlipper : MonoBehaviour
{
SpriteRenderer sp;
Vector3 prevPos;
void Start()
{
sp = GetComponentInChildren<SpriteRenderer>();
}
private void Update()
{
if ((transform.position - prevPos).x > 0.1f)
{
sp.flipX = false;
}
else if ((transform.position - prevPos).x < -0.1f)
{
sp.flipX = true;
}
prevPos = transform.position;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c66441ada081b6c4c841000e83cc2b7a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: