Pull request #26: Animation unites
Merge in CGD/gather-and-defend from animation_unites to main * commit 'e44264d66f2068dc53f341e5bb19684e2e3409db': ajout event animation, ajout classe Root qui sert de transition entre la classe Entity et l'animator. correction du merge request no message animations walk/idle/death/move working
This commit is contained in:
commit
525a1ba729
@ -2066,4 +2066,11 @@ AnimationClip:
|
||||
script: {fileID: 0}
|
||||
m_HasGenericRootTransform: 1
|
||||
m_HasMotionFloatCurves: 0
|
||||
m_Events: []
|
||||
m_Events:
|
||||
- time: 0.6166667
|
||||
functionName: ShotProjectile
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
|
||||
@ -1,5 +1,31 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1102 &-5723871321714695223
|
||||
AnimatorState:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: New State
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 0}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1102 &-5615459309368676638
|
||||
AnimatorState:
|
||||
serializedVersion: 6
|
||||
@ -10,7 +36,8 @@ AnimatorState:
|
||||
m_Name: walk
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_Transitions:
|
||||
- {fileID: 6351061945338306534}
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
@ -84,7 +111,8 @@ AnimatorState:
|
||||
m_Name: idle
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_Transitions:
|
||||
- {fileID: 1272373060093443428}
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
@ -126,6 +154,28 @@ AnimatorState:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!1101 &1272373060093443428
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions: []
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: 703164551053012985}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 1
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1107 &4042451101728204287
|
||||
AnimatorStateMachine:
|
||||
serializedVersion: 6
|
||||
@ -137,16 +187,19 @@ AnimatorStateMachine:
|
||||
m_ChildStates:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 703164551053012985}
|
||||
m_Position: {x: 260, y: 110, z: 0}
|
||||
m_Position: {x: 260, y: 170, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 1028912623824696338}
|
||||
m_Position: {x: 260, y: 50, z: 0}
|
||||
m_Position: {x: 260, y: 240, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -5615459309368676638}
|
||||
m_Position: {x: 260, y: -10, z: 0}
|
||||
m_Position: {x: 260, y: 90, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -4316900719387780663}
|
||||
m_Position: {x: 260, y: 170, z: 0}
|
||||
m_Position: {x: 260, y: 310, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -5723871321714695223}
|
||||
m_Position: {x: 704.1478, y: -596.24896, z: 0}
|
||||
m_ChildStateMachines: []
|
||||
m_AnyStateTransitions: []
|
||||
m_EntryTransitions: []
|
||||
@ -157,3 +210,25 @@ AnimatorStateMachine:
|
||||
m_ExitPosition: {x: 800, y: 120, z: 0}
|
||||
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||
m_DefaultState: {fileID: -5615459309368676638}
|
||||
--- !u!1101 &6351061945338306534
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions: []
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: -5615459309368676638}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.75
|
||||
m_HasExitTime: 1
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
|
||||
@ -4962,4 +4962,11 @@ AnimationClip:
|
||||
script: {fileID: 0}
|
||||
m_HasGenericRootTransform: 1
|
||||
m_HasMotionFloatCurves: 0
|
||||
m_Events: []
|
||||
m_Events:
|
||||
- time: 0.65
|
||||
functionName: Attack
|
||||
data:
|
||||
objectReferenceParameter: {fileID: 0}
|
||||
floatParameter: 0
|
||||
intParameter: 0
|
||||
messageOptions: 0
|
||||
|
||||
@ -1705,7 +1705,7 @@ AnimationClip:
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
m_HasAdditiveReferencePose: 0
|
||||
m_LoopTime: 1
|
||||
m_LoopTime: 0
|
||||
m_LoopBlend: 0
|
||||
m_LoopBlendOrientation: 0
|
||||
m_LoopBlendPositionY: 0
|
||||
|
||||
@ -774,7 +774,7 @@ AnimationClip:
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
m_HasAdditiveReferencePose: 0
|
||||
m_LoopTime: 1
|
||||
m_LoopTime: 0
|
||||
m_LoopBlend: 0
|
||||
m_LoopBlendOrientation: 0
|
||||
m_LoopBlendPositionY: 0
|
||||
|
||||
@ -733,7 +733,7 @@ AnimationClip:
|
||||
m_Level: 0
|
||||
m_CycleOffset: 0
|
||||
m_HasAdditiveReferencePose: 0
|
||||
m_LoopTime: 1
|
||||
m_LoopTime: 0
|
||||
m_LoopBlend: 0
|
||||
m_LoopBlendOrientation: 0
|
||||
m_LoopBlendPositionY: 0
|
||||
|
||||
@ -497,6 +497,7 @@ GameObject:
|
||||
- component: {fileID: 4594931196062474192}
|
||||
- component: {fileID: 3579562406765713002}
|
||||
- component: {fileID: 2002611158446544964}
|
||||
- component: {fileID: 7161153261079215068}
|
||||
m_Layer: 0
|
||||
m_Name: root
|
||||
m_TagString: Untagged
|
||||
@ -562,6 +563,19 @@ SortingGroup:
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 2
|
||||
--- !u!114 &7161153261079215068
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1531129202202440418}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_entity: {fileID: 313037212318601125}
|
||||
--- !u!1 &1776168629768863343
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -527,7 +527,6 @@ MonoBehaviour:
|
||||
_speed: 0
|
||||
_attack_damage: 10
|
||||
_attack_speed: 2
|
||||
_arrow: {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3}
|
||||
--- !u!1 &6962989255710846697
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -686,6 +685,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 6962989255883535387}
|
||||
- component: {fileID: 6962989255883535384}
|
||||
- component: {fileID: 8020346774049635274}
|
||||
m_Layer: 0
|
||||
m_Name: root
|
||||
m_TagString: Untagged
|
||||
@ -735,6 +735,20 @@ Animator:
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
m_KeepAnimatorStateOnDisable: 0
|
||||
m_WriteDefaultValuesOnDisable: 0
|
||||
--- !u!114 &8020346774049635274
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6962989255883535386}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_entity: {fileID: 5998513223176943995}
|
||||
_projectile: {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3}
|
||||
--- !u!1 &6962989255885988245
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -685,6 +685,7 @@ GameObject:
|
||||
m_Component:
|
||||
- component: {fileID: 6962989255883535387}
|
||||
- component: {fileID: 6962989255883535384}
|
||||
- component: {fileID: 5665233094155356672}
|
||||
m_Layer: 0
|
||||
m_Name: root
|
||||
m_TagString: Untagged
|
||||
@ -734,6 +735,19 @@ Animator:
|
||||
m_AllowConstantClipSamplingOptimization: 1
|
||||
m_KeepAnimatorStateOnDisable: 0
|
||||
m_WriteDefaultValuesOnDisable: 0
|
||||
--- !u!114 &5665233094155356672
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6962989255883535386}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_entity: {fileID: 8585520847943034727}
|
||||
--- !u!1 &6962989255885988245
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -4,8 +4,14 @@ using UnityEngine;
|
||||
|
||||
public class Ally : Entity
|
||||
{
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
void Update() {
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(IsEnemyDetected) {
|
||||
AttackEnemy();
|
||||
@ -13,17 +19,12 @@ public class Ally : Entity
|
||||
|
||||
}
|
||||
|
||||
void AttackEnemy() {
|
||||
void AttackEnemy()
|
||||
{
|
||||
//Attack Cooldown
|
||||
if(AttackSpeed < AttackSpeedWait) {
|
||||
|
||||
Enemy.Hp-=AttackDamage;
|
||||
Debug.Log("Opponent Hp = " + Enemy.Hp);
|
||||
|
||||
//Kill if no hp
|
||||
if(Enemy.Hp <= 0) {
|
||||
Destroy(Enemy);
|
||||
}
|
||||
Animation.PlayAttackAnim();
|
||||
|
||||
AttackSpeedWait = 0f;
|
||||
}
|
||||
|
||||
@ -5,41 +5,30 @@ using UnityEngine;
|
||||
public class Archer : Ally
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private GameObject _arrow;
|
||||
|
||||
private Rigidbody2D _rigidbodyAlly;
|
||||
private Rigidbody2D _rigidbodyOpponent;
|
||||
|
||||
void Start() {
|
||||
_rigidbodyAlly = GetComponent<Rigidbody2D>();
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
Animation = gameObject.AddComponent<AnimationEntity>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(IsEnemyDetected) {
|
||||
_rigidbodyOpponent = Enemy.GetComponent<Rigidbody2D>();
|
||||
AttackEnemy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AttackEnemy() {
|
||||
void AttackEnemy()
|
||||
{
|
||||
|
||||
//Attack Cooldown
|
||||
if(AttackSpeed < AttackSpeedWait) {
|
||||
|
||||
Animation.Attack();
|
||||
Animation.PlayAttackAnim();
|
||||
|
||||
GameObject _newArrow = Instantiate(_arrow, _rigidbodyAlly.position, Quaternion.identity);
|
||||
|
||||
//Warning : the Speed of the arrow is equal to the speed of this unit, if this unit need to move, use an other variable !
|
||||
_newArrow.GetComponent<Projectile>().Damage = AttackDamage;
|
||||
_newArrow.GetComponent<Projectile>().EnemySpeed = Enemy.Speed;
|
||||
_newArrow.GetComponent<Projectile>().VectorStart = _rigidbodyAlly.position;
|
||||
_newArrow.GetComponent<Projectile>().VectorEnd = _rigidbodyOpponent.position;
|
||||
_newArrow.GetComponent<Projectile>().Target = Enemy;
|
||||
|
||||
|
||||
AttackSpeedWait = 0f;
|
||||
|
||||
|
||||
@ -5,29 +5,52 @@ using UnityEngine;
|
||||
public class AnimationEntity : MonoBehaviour
|
||||
{
|
||||
|
||||
private Animator _animator_entity;
|
||||
private Animator _animatorEntity;
|
||||
private bool _doSomething = false;
|
||||
private bool _isDead = false;
|
||||
|
||||
void Start() {
|
||||
_animator_entity = GetComponentInChildren<Animator>();
|
||||
void Start()
|
||||
{
|
||||
_animatorEntity = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (_doSomething && _animator_entity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
|
||||
if (_doSomething && _animatorEntity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
|
||||
{
|
||||
Idle();
|
||||
PlayIdleAnim();
|
||||
_doSomething = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Idle() {
|
||||
_animator_entity.Play("idle", 0, 0f);
|
||||
public void PlayIdleAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
_animatorEntity.Play("idle", 0, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack() {
|
||||
_animator_entity.Play("attack", 0, 0f);
|
||||
public void PlayWalkAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
_animatorEntity.Play("walk", 0, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAttackAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
_animatorEntity.Play("attack", 0, 0f);
|
||||
_doSomething = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayDieAnim()
|
||||
{
|
||||
_animatorEntity.Play("die", 0, 0f);
|
||||
_doSomething = true;
|
||||
_isDead = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,30 +22,36 @@ public class Detection : MonoBehaviour
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
//Projectiles detection + damage deal
|
||||
if(_projectileDamage > 0 && other.gameObject.GetComponent<Entity>() == _entityLinked) {
|
||||
if(_entityLinked != null) {
|
||||
if(_projectileDamage > 0 && other.gameObject.GetComponent<Entity>() == _entityLinked) {
|
||||
|
||||
_entityLinked.Hit(_projectileDamage);
|
||||
//Kill if no hp
|
||||
if(other.gameObject.GetComponent<Entity>().Hp <= 0) {
|
||||
other.gameObject.GetComponent<Entity>().Death();
|
||||
_entityLinked = null;
|
||||
}
|
||||
|
||||
other.gameObject.GetComponent<Entity>().Hp -= _projectileDamage;
|
||||
//Kill if no hp
|
||||
if(other.gameObject.GetComponent<Entity>().Hp <= 0) {
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnTriggerStay2D(Collider2D other) {
|
||||
void OnTriggerStay2D(Collider2D other)
|
||||
{
|
||||
if(_entityLinked != null) {
|
||||
if(_entityLinked.Enemy == null) {
|
||||
//Detect the enemy and inform the Ally
|
||||
if (other.gameObject.tag == "Opponent" && _entityLinked is Ally) {
|
||||
_entityLinked.IsEnemyDetected = true;
|
||||
_entityLinked.Enemy = other.gameObject.GetComponent<Entity>();
|
||||
}
|
||||
|
||||
if(_entityLinked.Enemy == null) {
|
||||
//Detect the enemy and inform the Ally
|
||||
if (other.gameObject.tag == "Opponent" && _entityLinked is Ally) {
|
||||
_entityLinked.IsEnemyDetected = true;
|
||||
_entityLinked.Enemy = other.gameObject.GetComponent<Entity>();
|
||||
}
|
||||
|
||||
//Detect the enemy and inform the Opponent
|
||||
if (other.gameObject.tag == "Ally" && _entityLinked is Opponent) {
|
||||
_entityLinked.IsEnemyDetected = true;
|
||||
_entityLinked.Enemy = other.gameObject.GetComponent<Entity>();
|
||||
//Detect the enemy and inform the Opponent
|
||||
if (other.gameObject.tag == "Ally" && _entityLinked is Opponent) {
|
||||
_entityLinked.IsEnemyDetected = true;
|
||||
_entityLinked.Enemy = other.gameObject.GetComponent<Entity>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,9 +59,11 @@ public class Detection : MonoBehaviour
|
||||
|
||||
void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if(_projectileDamage == 0) {
|
||||
if ((other.gameObject.tag == "Opponent" && _entityLinked is Ally) || (other.gameObject.tag == "Ally" && _entityLinked is Opponent)) {
|
||||
_entityLinked.IsEnemyDetected = false;
|
||||
if(_entityLinked != null) {
|
||||
if(_projectileDamage == 0) {
|
||||
if ((other.gameObject.tag == "Opponent" && _entityLinked is Ally) || (other.gameObject.tag == "Ally" && _entityLinked is Opponent)) {
|
||||
_entityLinked.IsEnemyDetected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,11 +16,71 @@ public class Entity : LevelObject
|
||||
private float _attack_speed;
|
||||
private float _attack_speed_wait = 0f;
|
||||
private AnimationEntity _animation;
|
||||
private Shader _shaderGUItext;
|
||||
private Shader _shaderSpritesDefault;
|
||||
private SpriteRenderer[] _spriteRenderers;
|
||||
|
||||
//Enemy Spotted
|
||||
private bool _isEnemyDetected = false;
|
||||
private Entity _enemy;
|
||||
|
||||
//Methods
|
||||
public virtual void Start()
|
||||
{
|
||||
_spriteRenderers = GetComponentsInChildren<SpriteRenderer>();
|
||||
}
|
||||
|
||||
//Start the animation of death and the fading of the entity
|
||||
public void Death()
|
||||
{
|
||||
_animation.PlayDieAnim();
|
||||
Invoke("Dying", 0.1f);
|
||||
}
|
||||
|
||||
//Recursive method that fade the dying entity
|
||||
void Dying()
|
||||
{
|
||||
foreach (SpriteRenderer renderer in _spriteRenderers)
|
||||
{
|
||||
Color currentColor = renderer.color;
|
||||
currentColor.a = currentColor.a - 0.1f;
|
||||
renderer.color = currentColor;
|
||||
}
|
||||
|
||||
if(_spriteRenderers[0].color.a > 0f) {
|
||||
Invoke("Dying", 0.1f);
|
||||
}else {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//When hit : get damage and start a flash of light
|
||||
public void Hit(int damage)
|
||||
{
|
||||
|
||||
_hp-=damage;
|
||||
|
||||
_shaderGUItext = Shader.Find("GUI/Text Shader");
|
||||
_shaderSpritesDefault = Shader.Find("Sprites/Default");
|
||||
|
||||
foreach (SpriteRenderer renderer in _spriteRenderers)
|
||||
{
|
||||
renderer.material.shader = _shaderGUItext;
|
||||
}
|
||||
Invoke("ReturnNormalColor", 0.1f);
|
||||
}
|
||||
|
||||
//End the flash of light from the method above
|
||||
void ReturnNormalColor()
|
||||
{
|
||||
|
||||
foreach (SpriteRenderer renderer in _spriteRenderers)
|
||||
{
|
||||
renderer.material.shader = _shaderSpritesDefault;
|
||||
}
|
||||
}
|
||||
|
||||
//GETTERS AND SETTERS
|
||||
|
||||
public int Hp
|
||||
|
||||
@ -8,12 +8,16 @@ public class Opponent : Entity
|
||||
private Vector2 _movementVector = Vector2.zero;
|
||||
private Rigidbody2D _rigidbody;
|
||||
|
||||
void Start()
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
_rigidbody = GetComponent<Rigidbody2D>();
|
||||
Animation = gameObject.AddComponent<AnimationEntity>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
void Update()
|
||||
{
|
||||
|
||||
_movementVector.x = -Time.deltaTime * Speed;
|
||||
|
||||
@ -25,17 +29,12 @@ public class Opponent : Entity
|
||||
|
||||
}
|
||||
|
||||
void AttackEnemy() {
|
||||
void AttackEnemy()
|
||||
{
|
||||
//Attack Cooldown
|
||||
if(AttackSpeed < AttackSpeedWait)
|
||||
{
|
||||
Enemy.Hp-=AttackDamage;
|
||||
Debug.Log("Ally Hp = " + Enemy.Hp);
|
||||
|
||||
//Kill if no hp
|
||||
if(Enemy.Hp <= 0) {
|
||||
Destroy(Enemy);
|
||||
}
|
||||
Animation.PlayAttackAnim();
|
||||
|
||||
AttackSpeedWait = 0f;
|
||||
}
|
||||
|
||||
37
Assets/Scripts/Root.cs
Normal file
37
Assets/Scripts/Root.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Root : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private Entity _entity;
|
||||
[SerializeField]
|
||||
private GameObject _projectile;
|
||||
|
||||
void Attack() {
|
||||
_entity.Enemy.Hit( _entity.AttackDamage);
|
||||
if(_entity.Enemy.Hp <= 0) {
|
||||
_entity.Enemy.Death();
|
||||
_entity.IsEnemyDetected = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ShotProjectile() {
|
||||
Rigidbody2D _rigidbodyAlly;
|
||||
Rigidbody2D _rigidbodyOpponent;
|
||||
_rigidbodyAlly = _entity.GetComponent<Rigidbody2D>();
|
||||
_rigidbodyOpponent = _entity.Enemy.GetComponent<Rigidbody2D>();
|
||||
|
||||
GameObject _newArrow = Instantiate(_projectile, _rigidbodyAlly.position, Quaternion.identity);
|
||||
|
||||
//Warning : the Speed of the arrow is equal to the speed of this unit, if this unit need to move, use an other variable !
|
||||
_newArrow.GetComponent<Projectile>().Damage = _entity.AttackDamage;
|
||||
_newArrow.GetComponent<Projectile>().EnemySpeed = _entity.Enemy.Speed;
|
||||
_newArrow.GetComponent<Projectile>().VectorStart = _rigidbodyAlly.position;
|
||||
_newArrow.GetComponent<Projectile>().VectorEnd = _rigidbodyOpponent.position;
|
||||
_newArrow.GetComponent<Projectile>().Target = _entity.Enemy;
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Root.cs.meta
Normal file
11
Assets/Scripts/Root.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0fbd934c179894458914437255781c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user