Commit b2c0a92e authored by Max's avatar Max
Browse files

Added collider to all enemies and fixed shroombie melee hitbox

parent f503983d
......@@ -309,9 +309,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
facingRight: 0
meleeTiming: 0
verticalOffset: 0.5
horizontalOffset: 0.5
attackRangeX: 1
hitboxPrefab: {fileID: 2428752337564160461, guid: 90d04397d1b9f464496d46817624fa15,
type: 3}
horizontalOffset: 1
attackRangeX: 2
attackRangeY: 1
whatIsPlayer:
serializedVersion: 2
......@@ -1575,9 +1576,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
facingRight: 1
meleeTiming: 0
verticalOffset: 0.5
horizontalOffset: 0.5
attackRangeX: 1
hitboxPrefab: {fileID: 2428752337564160461, guid: 90d04397d1b9f464496d46817624fa15,
type: 3}
horizontalOffset: 1
attackRangeX: 2
attackRangeY: 1
whatIsPlayer:
serializedVersion: 2
......
......@@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 382294967272604787}
- component: {fileID: 382294967272604786}
- component: {fileID: 382294967272604789}
- component: {fileID: 7926794471850828057}
m_Layer: 0
m_Name: Crawler
m_TagString: Untagged
......@@ -99,3 +100,29 @@ Animator:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!61 &7926794471850828057
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 382294967272604784}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
......@@ -13,7 +13,7 @@ GameObject:
- component: {fileID: 2569753237885890404}
- component: {fileID: 2569753237885890407}
m_Layer: 9
m_Name: Pendushroom
m_Name: Metronom
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
......@@ -71,7 +71,7 @@ SpriteRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: 191ca67cc9f7fdc419104c53f032ef3e, type: 3}
m_Color: {r: 0, g: 1, b: 0.28193736, a: 1}
m_Color: {r: 0, g: 0.2830189, b: 0.07991121, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
......@@ -110,7 +110,7 @@ BoxCollider2D:
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_Offset: {x: 0, y: 0.4}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
......@@ -121,5 +121,5 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_Size: {x: 1, y: 0.2}
m_EdgeRadius: 0
......@@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 7591825399413244335}
- component: {fileID: 7591825399413244321}
- component: {fileID: 7591825399413244334}
- component: {fileID: 3753179524225600079}
m_Layer: 0
m_Name: Plant
m_TagString: Untagged
......@@ -95,6 +96,30 @@ MonoBehaviour:
shootingDirection: 0
sporePrefab: {fileID: 2702223633894697336, guid: f32f70a0ff463d14e9110eccc33a2143,
type: 3}
spores: []
timeBetweenSporeSpawns: 5
sporeSpeed: 1
--- !u!61 &3753179524225600079
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7591825399413244332}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2428752337564160461
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 8335460145205708057}
- component: {fileID: 5085368338825649577}
- component: {fileID: 4071811260565845692}
m_Layer: 9
m_Name: ShroombieHitBox
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &8335460145205708057
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2428752337564160461}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &5085368338825649577
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2428752337564160461}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &4071811260565845692
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2428752337564160461}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a09929a83c1071240be55555d7150973, type: 3}
m_Name:
m_EditorClassIdentifier:
hitboxTimer: 0.5
fileFormatVersion: 2
guid: 90d04397d1b9f464496d46817624fa15
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -519,8 +519,8 @@ Camera:
m_GameObject: {fileID: 382514589}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 2
m_BackGroundColor: {r: 0.085751146, g: 0.4433962, b: 0.094454154, a: 0}
m_ClearFlags: 1
m_BackGroundColor: {r: 0.08067818, g: 0.46226418, b: 0.08906464, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HitBoxLingering : MonoBehaviour
{
//wie lange die Hitbox existiert, bevor sie zerstört wird
public float hitboxTimer;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(hitboxTimer < 0)
{
Destroy(gameObject);
}
else
{
hitboxTimer -= Time.deltaTime;
}
}
}
fileFormatVersion: 2
guid: a09929a83c1071240be55555d7150973
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -15,16 +15,15 @@ public class ShroombieMeleeBehaviour : StateMachineBehaviour
//verschiebt das Erscheinen der Hitbox um diese Anzahl von Sekunden (zum Anpassen an Animation)
public float meleeTiming;
//wie lange die Hitbox noch da bleibt
public float hitBoxLingering;
private float timer;
private float hBTimer;
//Hitbox des Nahkampfs
public GameObject hitboxPrefab;
private GameObject hitbox;
//bool um zu schauen ob geschossen wurde
private bool done;
//Offset des Colliders zum Sprite
public float verticalOffset;
public float horizontalOffset;
//Radius des Angriffs
public float attackRangeX;
......@@ -39,7 +38,6 @@ public class ShroombieMeleeBehaviour : StateMachineBehaviour
player = GameObject.FindGameObjectWithTag("Player");
timer = meleeTiming;
hBTimer = hitBoxLingering;
done = false;
myTransform = animator.transform;
......@@ -52,49 +50,27 @@ public class ShroombieMeleeBehaviour : StateMachineBehaviour
if(timer < 0f && !done)
{
//Position und Größe des BoxColliders
//Position des BoxColliders
Vector3 attackPos;
Vector3 size = new Vector3(attackRangeX, attackRangeY, 0f);
//ändert die Angriffsposition je nach Blickrichtung
if (facingRight)
{
attackPos = myTransform.position + horizontalOffset * Vector3.right + verticalOffset * Vector3.up;
attackPos = myTransform.position + horizontalOffset * Vector3.right;
}
else
{
attackPos = myTransform.position - horizontalOffset * Vector3.right + verticalOffset * Vector3.up;
attackPos = myTransform.position - horizontalOffset * Vector3.right;
}
//lässt einen BoxCollider erscheinen und setzt alle Kollisionen in das Array
Collider2D[] playerToDamage = Physics2D.OverlapBoxAll(attackPos, size, whatIsPlayer);
//Visualisierung der Hitbox für den Szenemodus
Vector3 topRight = new Vector3(attackPos.x + (attackRangeX / 2), attackPos.y + (attackRangeY / 2), attackPos.z);
Vector3 topLeft = new Vector3(attackPos.x - (attackRangeX / 2), attackPos.y + (attackRangeY / 2), attackPos.z);
Vector3 bottomLeft = new Vector3(attackPos.x - (attackRangeX / 2), attackPos.y - (attackRangeY / 2), attackPos.z);
Vector3 bottomRight = new Vector3(attackPos.x + (attackRangeX / 2), attackPos.y - (attackRangeY / 2), attackPos.z);
Debug.DrawLine(topRight, topLeft);
Debug.DrawLine(topLeft, bottomLeft);
Debug.DrawLine(bottomLeft, bottomRight);
Debug.DrawLine(bottomRight, topRight);
for (int i = 0; i < playerToDamage.Length; i++)
if (hitbox == null)
{
//TODO: Spieler Schaden hinzufügen
hitbox = Instantiate(hitboxPrefab, attackPos, Quaternion.identity);
}
//done auf true setzen, wenn die Hitbox nicht mehr erscheinen soll
if (hBTimer < 0)
{
hBTimer = hitBoxLingering;
timer = meleeTiming;
done = true;
}
else
{
hBTimer -= Time.deltaTime;
}
timer = meleeTiming;
done = true;
}
else
{
......
Supports Markdown
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