- component: {fileID: 936765979}
- component: {fileID: 936765980}
- component: {fileID: 936765981}
+ - component: {fileID: 936765982}
m_Layer: 0
m_Name: maus
m_TagString: Player
- {fileID: 397286150}
fullHeart: {fileID: 21300000, guid: 46a74d1428d29c342a3d11cb96df7622, type: 3}
emptyHeart: {fileID: 21300000, guid: f0a4f4e3dcd85cb4cba379c2b8452f70, type: 3}
- invincible: 0
--- !u!114 &936765977
MonoBehaviour:
m_ObjectHideFlags: 0
m_Name:
m_EditorClassIdentifier:
levelGeschafft: {fileID: 423319633}
+--- !u!114 &936765982
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 936765968}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: 24ecf8abffd3176449dbce52b3f21663, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ invincible: 0
+ invincibilityFramesNumber: 4
--- !u!95 &936765983
Animator:
serializedVersion: 3
PowerUps powerUps;
- public bool invincible;
+ InvincibilityFrames invincibility;
private void Start()
{
powerUps = GetComponent<PowerUps>();
+ invincibility = GetComponent<InvincibilityFrames>();
}
// Update is called once per frame
//Bei Ber?hrung mit einem Gegner wird die Gesundheit um 1 verringert
private void OnCollisionEnter2D(Collision2D collision)
{
- if(collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Boss"))
+ if(collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Boss") && invincibility == false)
{
mouseHealth--;
- invincible = true;
powerUps.mouseIsGardener = false;
+ invincibility.invincible = true;
+ }
+
+ if(invincibility.invincible == true)
+ {
+ if (collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Boss"))
+ {
+ Physics2D.IgnoreCollision(collision.collider, collision.collider);
+ }
}
}
}
public class InvincibilityFrames : MonoBehaviour
{
SpriteRenderer spriteRenderer;
-
Health health;
+ public bool invincible;
+
+ public float invincibilityFramesNumber = 2;
+ private float invincibilityFrames;
+
// Start is called before the first frame update
void Start()
{
// Update is called once per frame
void Update()
{
- if(health.invincible == true)
+ if(invincible == true)
{
-
+ invincibilityFrames = invincibilityFramesNumber;
+ invincibilityFrames -= Time.deltaTime;
+ if(invincibilityFrames > 0)
+ {
+ invincible = true;
+ }
+ if (invincibilityFrames == 0)
+ {
+ invincible = false;
+ }
}
+
+ print(invincible);
}
}