Commit 4cbcfa99 authored by 15김민규's avatar 15김민규

피격시 방향은 항상 플레이어를 바라보도록 함

parent 16d5c2a0
...@@ -45,6 +45,17 @@ AnimatorController: ...@@ -45,6 +45,17 @@ AnimatorController:
m_IKPass: 0 m_IKPass: 0
m_SyncedLayerAffectsTiming: 0 m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 9100000}
--- !u!114 &114316214165794054
MonoBehaviour:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 752c7d4f7a0f1444c84cadeae1fab1d7, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &114878841526562312 --- !u!114 &114878841526562312
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
...@@ -195,7 +206,8 @@ AnimatorState: ...@@ -195,7 +206,8 @@ AnimatorState:
m_CycleOffset: 0 m_CycleOffset: 0
m_Transitions: m_Transitions:
- {fileID: 1101117024733671452} - {fileID: 1101117024733671452}
m_StateMachineBehaviours: [] m_StateMachineBehaviours:
- {fileID: 114316214165794054}
m_Position: {x: 50, y: 50, z: 0} m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0 m_IKOnFeet: 0
m_WriteDefaultValues: 1 m_WriteDefaultValues: 1
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Damaged : StateMachineBehaviour {
RuntimeAnimatorController ac;
float knockbackTime;
Vector3 leftsideAngle = new Vector3(0, 0, 0);
Vector3 rightsideAngle = new Vector3(0, 180, 0);
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
ac = animator.runtimeAnimatorController;
foreach(var clip in ac.animationClips)
{
if (clip.name.Contains("Damaged"))
{
knockbackTime = clip.length;
}
}
Transform playerTransform = EnemyManager.Instance.player.transform;
Transform pivotTransform = animator.transform.parent;
pivotTransform.eulerAngles = (playerTransform.position.x - pivotTransform.position.x < 0) ? leftsideAngle : rightsideAngle;
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateMove is called right after Animator.OnAnimatorMove(). Code that processes and affects root motion should be implemented here
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateIK is called right after Animator.OnAnimatorIK(). Code that sets up animation IK (inverse kinematics) should be implemented here.
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
}
fileFormatVersion: 2
guid: 752c7d4f7a0f1444c84cadeae1fab1d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -9,7 +9,7 @@ public class MeleeTrack : StateMachineBehaviour { ...@@ -9,7 +9,7 @@ public class MeleeTrack : StateMachineBehaviour {
Vector3 leftsideAngle = new Vector3(0, 0, 0); Vector3 leftsideAngle = new Vector3(0, 0, 0);
Vector3 rightsideAngle = new Vector3(0, 180, 0); Vector3 rightsideAngle = new Vector3(0, 180, 0);
readonly float dirChangeTime = 0.5f; readonly float dirChangeTime = 0.5f;
Transform animatorRoot; Transform pivotTransform;
readonly int maxFrame = 10; readonly int maxFrame = 10;
int frameCounter; int frameCounter;
Vector2 centerOfBody; Vector2 centerOfBody;
...@@ -20,9 +20,9 @@ public class MeleeTrack : StateMachineBehaviour { ...@@ -20,9 +20,9 @@ public class MeleeTrack : StateMachineBehaviour {
attackRange = animator.GetComponent<Enemy>().attackRange; attackRange = animator.GetComponent<Enemy>().attackRange;
player = EnemyManager.Instance.player; player = EnemyManager.Instance.player;
animatorRoot = animator.transform.parent; pivotTransform = animator.transform.parent;
float halfHeight = animatorRoot.gameObject.GetComponent<BoxCollider2D>().size.y / 2.0f; float halfHeight = pivotTransform.gameObject.GetComponent<BoxCollider2D>().size.y / 2.0f;
Vector2 rootPosition2D = animatorRoot.position; Vector2 rootPosition2D = pivotTransform.position;
centerOfBody = new Vector2(0, halfHeight) + rootPosition2D; centerOfBody = new Vector2(0, halfHeight) + rootPosition2D;
frameCounter = 0; frameCounter = 0;
} }
...@@ -32,7 +32,7 @@ public class MeleeTrack : StateMachineBehaviour { ...@@ -32,7 +32,7 @@ public class MeleeTrack : StateMachineBehaviour {
frameCounter += 1; frameCounter += 1;
if (frameCounter >= maxFrame) if (frameCounter >= maxFrame)
{ {
animatorRoot.eulerAngles = (player.transform.position.x - animatorRoot.position.x < 0) ? leftsideAngle : rightsideAngle; pivotTransform.eulerAngles = (player.transform.position.x - pivotTransform.position.x < 0) ? leftsideAngle : rightsideAngle;
frameCounter = 0; frameCounter = 0;
} }
if (animator.GetComponent<Enemy>().playerDistance < attackRange) if (animator.GetComponent<Enemy>().playerDistance < attackRange)
...@@ -41,9 +41,9 @@ public class MeleeTrack : StateMachineBehaviour { ...@@ -41,9 +41,9 @@ public class MeleeTrack : StateMachineBehaviour {
return; return;
} }
Vector2 currPosition = animatorRoot.position; Vector2 currPosition = pivotTransform.position;
Vector2 movingDistance = animatorRoot.right * trackSpeed * Time.deltaTime * -1; Vector2 movingDistance = pivotTransform.right * trackSpeed * Time.deltaTime * -1;
animatorRoot.gameObject.GetComponent<Rigidbody2D>().MovePosition(currPosition + movingDistance); pivotTransform.gameObject.GetComponent<Rigidbody2D>().MovePosition(currPosition + movingDistance);
} }
......
...@@ -40,8 +40,6 @@ public class Enemy : MonoBehaviour { ...@@ -40,8 +40,6 @@ public class Enemy : MonoBehaviour {
// for animation // for animation
[HideInInspector] [HideInInspector]
public float playerDistance; public float playerDistance;
public bool gotKnockback;
RuntimeAnimatorController ac;
// drop item // drop item
...@@ -51,7 +49,6 @@ public class Enemy : MonoBehaviour { ...@@ -51,7 +49,6 @@ public class Enemy : MonoBehaviour {
private void Awake() private void Awake()
{ {
enemyManager = EnemyManager.Instance; enemyManager = EnemyManager.Instance;
ac = GetComponent<Animator>().runtimeAnimatorController;
} }
private void Start() private void Start()
...@@ -63,10 +60,6 @@ public class Enemy : MonoBehaviour { ...@@ -63,10 +60,6 @@ public class Enemy : MonoBehaviour {
private void Update() private void Update()
{ {
playerDistance = Vector2.Distance(enemyManager.player.transform.position, transform.parent.position); playerDistance = Vector2.Distance(enemyManager.player.transform.position, transform.parent.position);
if (gotKnockback)
{
}
} }
// hit by player or debuff // hit by player or debuff
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment