Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Assets/Prefabs/Character2.0/CharacterSG.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ GameObject:
- component: {fileID: 3880474832234692612}
- component: {fileID: 4316165558744359977}
- component: {fileID: 9173539896847060255}
- component: {fileID: 3046411758469487390}
m_Layer: 7
m_Name: Shotgun
m_TagString: Untagged
Expand Down Expand Up @@ -322,7 +323,26 @@ MonoBehaviour:
timeBetweenShots: 1
maxDeviation: 20
damage: 10
firePointCount: 20
muzzleParticles: {fileID: 0}
firePointCount: 5
--- !u!114 &3046411758469487390
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1350729860219815044}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2694f0c1032d48b43b0f5dcac468c494, type: 3}
m_Name:
m_EditorClassIdentifier:
fireForce: 40
bulletPrefab: {fileID: 6851814959954085267, guid: 32c153dc629fd6d41b9d137b1e388035, type: 3}
firePoint: {fileID: 5558555831162425253}
timeBetweenShots: 0.02
maxDeviation: 10
damage: 20
--- !u!1 &1951664781426303919
GameObject:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions Assets/Prefabs/Enemys/Crawler.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ MonoBehaviour:
healthBar: {fileID: 8610740355228082374}
transformToCrawler: {fileID: 0}
bloodPuddleHit: {fileID: 1950607216614953820, guid: 52ec8f3c7f50e4247944d5d0885612eb, type: 3}
experiencePoint: 20
--- !u!58 &-2979630653874237575
CircleCollider2D:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions Assets/Prefabs/Enemys/Runner.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ MonoBehaviour:
healthBar: {fileID: 8610740355228082374}
transformToCrawler: {fileID: 0}
bloodPuddleHit: {fileID: 1950607216614953820, guid: 52ec8f3c7f50e4247944d5d0885612eb, type: 3}
experiencePoint: 40
--- !u!58 &-2979630653874237575
CircleCollider2D:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions Assets/Prefabs/Enemys/Zombie.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ MonoBehaviour:
healthBar: {fileID: 8610740355228082374}
transformToCrawler: {fileID: 1642046387127829927}
bloodPuddleHit: {fileID: 1950607216614953820, guid: 52ec8f3c7f50e4247944d5d0885612eb, type: 3}
experiencePoint: 20
--- !u!58 &-2979630653874237575
CircleCollider2D:
m_ObjectHideFlags: 0
Expand Down
4 changes: 3 additions & 1 deletion Assets/Scripts/Enemy/EnemyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ private void Awake()

// Suchen des Spielers als Ziel
GameObject playerObject = GameObject.FindGameObjectWithTag("Player");
PlayerSwitcher playerManager = GameObject.Find("PlayerSwitcher").GetComponent<PlayerSwitcher>();

if (playerObject != null)
{
playerController = playerObject.GetComponent<Player>();
}

if (playerController != null && !playerController.GetIsDead())
{
target = playerController.transform;
target = playerManager.playerClass.position;
}

InvokeRepeating("UpdatePath", 0f, 0.5f); // Aktualisierung des Pfads alle 0,5 Sekunden
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Enemy/EnemyHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class EnemyHealth : MonoBehaviour
private Quaternion deathRotation; // Speichert die Rotation des Objekts vor der Zerstörung
private Vector3 deathScale; // Speichert die Skalierung des Objekts vor der Zerstörung
private KillCounter killCounter;
public int experiencePoint;
private PlayerSwitcher playerManager;

void Start()
{
Expand All @@ -33,6 +35,7 @@ void Start()
sprite = GetComponent<SpriteRenderer>();
killCounter = FindObjectOfType<KillCounter>();
cursorFeedback = FindObjectOfType<CursorFeedback>();
playerManager = GameObject.Find("PlayerSwitcher").GetComponent<PlayerSwitcher>();
}

private void OnCollisionEnter2D(Collision2D collision)
Expand Down Expand Up @@ -78,6 +81,8 @@ public void TakeDamage(int damage)
{
Instantiate(itemDrop, transform.position, Quaternion.identity);
}
Debug.Log("Experience Points given: " + experiencePoint);
playerManager.playerClass.AddExpPoints(experiencePoint);
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion Assets/Scripts/Player/BulletSG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ private void OnCollisionEnter2D(Collision2D collision)
//Debug.Log(collision.gameObject);
if (collision.gameObject.CompareTag("Enemy"))
{
collision.gameObject.GetComponent<EnemyHealth>().TakeDamage(GameObject.FindGameObjectWithTag("Player").GetComponentInChildren<WeaponSG>().damage);
var enemy = collision.gameObject.GetComponent<EnemyHealth>();
if (enemy.currentHealth > 0)
{
enemy.TakeDamage(GameObject.FindGameObjectWithTag("Player").GetComponentInChildren<WeaponSG>().damage);
}
}
else if (!collision.gameObject.CompareTag("Player") && !collision.gameObject.CompareTag("Bullet"))
{
Expand Down
22 changes: 16 additions & 6 deletions Assets/Scripts/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Player : MonoBehaviour

public int maxHealth = 100;
public int currentHealth;
public static int currency;
public static int currency = 100;

public HealthBar healthBar;
public SpriteRenderer playerSprite;
Expand All @@ -23,15 +23,23 @@ public class Player : MonoBehaviour
private bool isDead = false;
private bool impactForceBool = false;
private Quaternion initialRotation; // Speichert die Rotation des ursprünglichen Objekts

private PlayerSwitcher playerManager;


// Start is called before the first frame update
void Start()
{
currentHealth = maxHealth;
playerManager = GameObject.Find("PlayerSwitcher").GetComponent<PlayerSwitcher>();
PlayerClass playerClass = playerManager.playerClass;
currentHealth = playerClass.maxHealth;
currency = playerClass.GetCurrency();
Debug.Log("maxHealth " + maxHealth);
healthBar.SetMaxHealth(maxHealth);

if (currentHealth < maxHealth)
{
//Debug.Log("True");
healthBar.SetHealth(currentHealth);
}
rb = GetComponent<Rigidbody2D>();
}

Expand All @@ -42,11 +50,12 @@ public void TakeDamage(int damage)
currentHealth = maxHealth;
}
healthBar.SetHealth(currentHealth);
playerManager.playerClass.SetHealth(currentHealth);
ApplyImpact(damage * impactForceMultiplier);
StartCoroutine(HitFlash());


//Debug.Log("currentHealth " + currentHealth);
Debug.Log("currentHealth " + currentHealth);
if (currentHealth <= 0)
{
isDead = true;
Expand Down Expand Up @@ -75,7 +84,7 @@ public int GetMaxHealth(){
}
public int GetCoins()
{
return currency;
return playerManager.playerClass.GetCurrency();
}
private IEnumerator HitFlash()
{
Expand Down Expand Up @@ -111,6 +120,7 @@ public void SetCurrentHealth(int currentHealth){

public void setCurrency(int value) {
currency = currency + value;
playerManager.playerClass.SetCurrency(currency);
//Debug.Log("Currency: " + currency);
}

Expand Down
45 changes: 43 additions & 2 deletions Assets/Scripts/Player/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ public class Weapon : MonoBehaviour
private CameraShake cameraShake;
private Recoil recoil;
private ParticleSystem muzzleParticles;
private int level = 1;
private WeaponSG newInstance;

private void Start()
{
cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
cameraShake = Camera.main.GetComponent<CameraShake>();
Transform firePointChild = transform.Find("FirePoint");
level = 1;
if (firePointChild != null)
{
muzzleParticles = firePointChild.GetComponentInChildren<ParticleSystem>();
Expand All @@ -27,8 +30,15 @@ private void Start()
{
Debug.Log("Muzzle null");
}
muzzleParticles.gameObject.SetActive(false);

if (transform.gameObject.TryGetComponent<WeaponSG>(out WeaponSG instance))
{
newInstance = instance;
newInstance.muzzleParticles = muzzleParticles;
newInstance.damage = damage;
newInstance.timeBetweenShots = timeBetweenShots;
}
muzzleParticles.gameObject.SetActive(false);
recoil = GetComponentInParent<Recoil>();
}

Expand All @@ -38,7 +48,15 @@ private void Update()
if (Input.GetButton("Fire1") && timeSinceLastShot >= timeBetweenShots)
{
muzzleParticles.gameObject.SetActive(true);
Shoot();
if (newInstance != null && transform.gameObject.name == "Shotgun")
{
newInstance.Shoot();
}
else
{
Shoot();
}

timeSinceLastShot = 0f;
}
}
Expand Down Expand Up @@ -81,5 +99,28 @@ private void Shoot()
public void SetDamage(int value)
{
damage = damage + value;
if (newInstance != null)
{
newInstance.damage = damage;
}
}

public void SetTimeBetweenShots(float value)
{
timeBetweenShots -= value;
if (newInstance != null)
{
newInstance.timeBetweenShots = timeBetweenShots;
}
}

public void AddLevel(int level)
{
this.level += level;
}

public int GetLevel()
{
return level;
}
}
43 changes: 11 additions & 32 deletions Assets/Scripts/Player/WeaponSG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,13 @@ public class WeaponSG : MonoBehaviour
private float timeSinceLastShot = Mathf.Infinity; // Anfangswert auf unendlich setzen
private CameraShake cameraShake;
private Recoil recoil;
private ParticleSystem muzzleParticles;
public ParticleSystem muzzleParticles;
public int firePointCount = 5;

private void Start()
{
cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
cameraShake = Camera.main.GetComponent<CameraShake>();
Transform firePointChild = transform.Find("FirePoint");
if (firePointChild != null)
{
muzzleParticles = firePointChild.GetComponentInChildren<ParticleSystem>();
}
else
{
Debug.Log("Muzzle = null");
}
muzzleParticles.gameObject.SetActive(false);
recoil = GetComponentInParent<Recoil>();
}

private void Update()
{

timeSinceLastShot += Time.deltaTime;
if (Input.GetButton("Fire1") && timeSinceLastShot >= timeBetweenShots)
{
muzzleParticles.gameObject.SetActive(true);
Shoot();
timeSinceLastShot = 0f;
}
}

private void Shoot()
private int level = 1;



public void Shoot()
{
for (int i = 0; i < firePointCount; i++)
{
Expand Down Expand Up @@ -82,4 +56,9 @@ public void SetDamage(int value)
{
damage = damage + value;
}

public void AddLevel(int level)
{
this.level += level;
}
}
34 changes: 28 additions & 6 deletions Assets/Scripts/SceneManagement/PlayerSwitcher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using Vector3 = System.Numerics.Vector3;

Expand All @@ -10,20 +12,31 @@ public class PlayerSwitcher : MonoBehaviour
private UnityEngine.Vector3 playerPosition;
private Quaternion playerRotation;
private CameraController camController;

public PlayerClass playerClass;
private float damageAR;
//public EnemyController enemController;
public EnemyController enemController;

private void Start()
{
camController = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<CameraController>();
// Den ersten Player auswählen
currentPlayer = GameObject.FindGameObjectWithTag("Player");
//enemController = GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyController>();
playerClass = new PlayerClass(currentPlayer.GetComponent<Player>().maxHealth, currentPlayer);
camController.SetTarget(playerClass.position);

//enemController.SetTarget(playerClass.position);
}

private void Update()
{
// Player wechseln basierend auf den Tasteneingaben
playerClass.hasLeveledUp();
if (currentPlayer != null)
{
playerClass.SetPosition(currentPlayer.transform.position);
//Debug.Log("Position: " + playerClass.position.position);
}
if (Input.GetKeyDown(KeyCode.Alpha1))
{
SwitchPlayer(0);
Expand All @@ -45,19 +58,28 @@ private void Update()
private void SwitchPlayer(int index)
{
// Überprüfen, ob der Index gültig ist
GameObject newPlayer;
if (index >= 0 && index < playerPrefabs.Length)
{
// Den aktuellen Player zerstören, falls vorhanden
if (currentPlayer != null)
{
playerPosition = currentPlayer.transform.position;
playerRotation = currentPlayer.transform.rotation;
Destroy(currentPlayer);
}

// Das neue Player-Prefab instanziieren und als aktuellen Player setzen
currentPlayer = Instantiate(playerPrefabs[index], playerPosition, playerRotation);
camController.SetTarget(currentPlayer.transform);
currentPlayer.SetActive(false);
int health = currentPlayer.GetComponent<Player>().currentHealth;
currentPlayer = transform.GetComponentInChildren<Transform>().Find(playerPrefabs[index].name).GameObject();
currentPlayer.SetActive(true);
currentPlayer.transform.position = playerPosition;
currentPlayer.transform.rotation = playerRotation;
currentPlayer.GetComponent<Player>().currentHealth = health;
currentPlayer.GetComponent<Player>().healthBar.SetHealth(health);

//playerClass.SetPosition(currentPlayer.transform.position);
//camController.SetTarget(currentPlayer.transform);
//enemController.SetTarget(currentPlayer.transform);
}
}
Expand Down
Loading