1
Fork 0

Slimes should attack, but for some reason they don't

No idea
This commit is contained in:
Lorenzo Balugani 2019-04-29 15:00:35 +02:00
parent 95d63ac62b
commit 897df5f308
5 changed files with 31 additions and 54 deletions

View file

@ -195,7 +195,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0cb881aee511ed643880a50159d731b7, type: 3}
m_Name:
m_EditorClassIdentifier:
damage: 1
damage: 4
--- !u!95 &7684473867237801912
Animator:
serializedVersion: 3

View file

@ -98,4 +98,4 @@ MonoBehaviour:
hp: 1
hpChange: -1
maxHpChange: -1
damage: 3
damage: 7

View file

@ -151,7 +151,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8182065399967645508}
m_RootOrder: 3
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
@ -184,7 +184,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 1, b: 0, a: 1}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
@ -195,10 +195,10 @@ MonoBehaviour:
m_Type: 3
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 2
m_FillMethod: 0
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_FillOrigin: 1
m_UseSpriteMesh: 0
--- !u!222 &1332612188
CanvasRenderer:
@ -239,7 +239,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8182065399967645508}
m_RootOrder: 2
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
@ -272,7 +272,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_Color: {r: 0.3962264, g: 0, b: 0, a: 1}
m_RaycastTarget: 0
m_OnCullStateChanged:
m_PersistentCalls:
@ -283,10 +283,10 @@ MonoBehaviour:
m_Type: 3
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 2
m_FillMethod: 0
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_FillOrigin: 1
m_UseSpriteMesh: 0
--- !u!222 &2051317737
CanvasRenderer:
@ -338,7 +338,6 @@ GameObject:
- component: {fileID: 7203168577643633308}
- component: {fileID: 4061326455747354953}
- component: {fileID: 2984726599447885319}
- component: {fileID: 2392633072578011031}
m_Layer: 5
m_Name: Filled HP Bar
m_TagString: Untagged
@ -346,19 +345,6 @@ GameObject:
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &2392633072578011031
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1313580544782099720}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cbf8b0d2fd980e14f9956f5345d82ddc, type: 3}
m_Name:
m_EditorClassIdentifier:
max: 0
--- !u!114 &2984726599447885319
MonoBehaviour:
m_ObjectHideFlags: 0
@ -413,7 +399,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8182065399967645508}
m_RootOrder: 1
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
@ -609,7 +595,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8182065399967645508}
m_RootOrder: 0
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 0}
m_AnchorMax: {x: 1, y: 0}
@ -721,10 +707,10 @@ RectTransform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 7203168577643633308}
- {fileID: 3195245192869872480}
- {fileID: 2051317734}
- {fileID: 1332612185}
- {fileID: 7203168577643633308}
m_Father: {fileID: 8182065398968123531}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View file

@ -12,6 +12,7 @@ public class EntityMonsterSlime : EntityMonster
public float moveChance = 0.5f;
public float visionRange = 4f;
public float damage = 1f;
public GameObject attackAnimation;
protected EntityPlayer player;
@ -38,18 +39,24 @@ public class EntityMonsterSlime : EntityMonster
}
}
else {
int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
transform.Translate(Vector3.left);
if(Vector3.Distance(player.transform.position, transform.position) > 2){
int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
transform.Translate(Vector3.left);
}
else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){
transform.Translate(Vector3.right);
}
else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){
transform.Translate(Vector3.up);
}
else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){
transform.Translate(Vector3.down);
}
}
else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){
transform.Translate(Vector3.right);
}
else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){
transform.Translate(Vector3.up);
}
else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){
transform.Translate(Vector3.down);
else{
float damage_done = Random.value * damage;
player.hp -= damage;
}
}
}

View file

@ -9,8 +9,6 @@ public enum ControlMode {
public class EntityPlayer : Entity
{
public Dictionary<InventoryItems, int> inventory;
public InventoryItems selectedItem;
protected ControlMode controlMode;
protected Animator animator;
@ -18,29 +16,15 @@ public class EntityPlayer : Entity
base.Start();
animator = GetComponent<Animator>();
controlMode = ControlMode.Move;
//Init inventory
inventory.Add(InventoryItems.HealthPotion, 0);
}
protected void Update()
{
CheckForControlModeChange();
CheckForInventoryInput();
if(controlMode == ControlMode.Move) CheckForMovementInput();
if(controlMode == ControlMode.Attack) CheckForAttackInput();
}
protected void CheckForInventoryInput() {
if(Input.GetKeyDown(KeyCode.X)) {
if(selectedItem == InventoryItems.Empty) {
selectedItem = 0;
}
else {
selectedItem += 1;
}
}
}
protected void CheckForControlModeChange() {
if(Input.GetKeyDown(KeyCode.Escape)) {
controlMode = ControlMode.Move;