MOD: Sprites hinzugefügt
MOD: Gegner platziert
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
public class EnemyMovementMelee : MonoBehaviour
|
||||
{
|
||||
public GameObject player;
|
||||
@@ -10,34 +11,26 @@ public class EnemyMovementMelee : MonoBehaviour
|
||||
|
||||
private float distance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
void Start()
|
||||
{
|
||||
enemyStats = GetComponent<EnemyStats>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(player != null){
|
||||
// Calculate the distance between the enemy and the player
|
||||
|
||||
distance = Vector2.Distance(transform.position, player.transform.position);
|
||||
|
||||
// Get the direction to the player by subtracting the enemy's position from the player's position
|
||||
Vector2 direction = player.transform.position - transform.position;
|
||||
direction.Normalize(); // Normalize the direction vector
|
||||
direction.Normalize();
|
||||
|
||||
// Calculate the angle to rotate the enemy to face the player
|
||||
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
|
||||
|
||||
// If the player is within a certain range, move towards them
|
||||
if (distance < targetDistance)
|
||||
{
|
||||
// Move the enemy towards the player's position
|
||||
transform.position = Vector2.MoveTowards(transform.position, player.transform.position, enemyStats.speed * Time.deltaTime);
|
||||
|
||||
// Rotate the enemy to face the player
|
||||
transform.rotation = Quaternion.Euler(Vector3.forward * angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
public class EnemyStats : MonoBehaviour
|
||||
{
|
||||
public Enemy enemy;
|
||||
@@ -16,7 +17,7 @@ public class EnemyStats : MonoBehaviour
|
||||
damage = enemy.getDamage();
|
||||
}
|
||||
|
||||
//Für Später
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
if (other.gameObject.CompareTag("Bullet")){
|
||||
BulletScript bulletScript = other.gameObject.GetComponent<BulletScript>();
|
||||
|
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Ben Keller
|
||||
public class PlayerMover : MonoBehaviour
|
||||
{
|
||||
public KeyCode up = KeyCode.W;
|
||||
@@ -18,7 +19,7 @@ public class PlayerMover : MonoBehaviour
|
||||
|
||||
public Player player;
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
@@ -26,7 +27,7 @@ public class PlayerMover : MonoBehaviour
|
||||
speed = playerStats.speed;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
void Update()
|
||||
{
|
||||
Move();
|
||||
@@ -51,7 +52,7 @@ public class PlayerMover : MonoBehaviour
|
||||
}
|
||||
|
||||
if(moveDirection.magnitude > 1){
|
||||
moveDirection.Normalize(); // Normalize if diagonal to avoid faster movement
|
||||
moveDirection.Normalize();
|
||||
}
|
||||
|
||||
rb.velocity = moveDirection * speed;
|
||||
|
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
public class PlayerStats : MonoBehaviour
|
||||
{
|
||||
public Player player;
|
||||
@@ -13,7 +14,7 @@ public class PlayerStats : MonoBehaviour
|
||||
|
||||
private bool isTakingDamage = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
|
||||
void Start()
|
||||
{
|
||||
health = player.getCurrentHealth();
|
||||
|
@@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.IO.LowLevel.Unsafe;
|
||||
using UnityEngine;
|
||||
|
||||
//Ben Keller
|
||||
public class Shooting : MonoBehaviour
|
||||
{
|
||||
private Camera mainCam;
|
||||
@@ -14,14 +16,19 @@ public class Shooting : MonoBehaviour
|
||||
|
||||
public PlayerStats playerStats;
|
||||
|
||||
// Start is called before the first frame update
|
||||
SpriteRenderer spriteRenderer;
|
||||
|
||||
public Transform muzzle;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
mainCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
|
||||
playerStats = gameObject.GetComponentInParent<PlayerStats>();
|
||||
spriteRenderer = gameObject.GetComponentInChildren<SpriteRenderer>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
||||
void Update()
|
||||
{
|
||||
mousePos = mainCam.ScreenToWorldPoint(Input.mousePosition);
|
||||
@@ -32,6 +39,25 @@ public class Shooting : MonoBehaviour
|
||||
|
||||
transform.rotation = Quaternion.Euler(0, 0, rotZ);
|
||||
|
||||
flip();
|
||||
|
||||
fire();
|
||||
}
|
||||
|
||||
void flip(){
|
||||
if (mousePos.x < transform.position.x)
|
||||
{
|
||||
spriteRenderer.flipY = true;
|
||||
muzzle.localPosition = new Vector3(1.65f, -0.14f, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
spriteRenderer.flipY = false;
|
||||
muzzle.localPosition = new Vector3(1.65f, 0.14f, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void fire(){
|
||||
if(!canFire){
|
||||
timer += Time.deltaTime;
|
||||
if(timer > playerStats.fireRate){
|
||||
|
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
[CreateAssetMenu(fileName = "Enemy", menuName = "Enemy/Enemy", order = 0)]
|
||||
public class Enemy : ScriptableObject
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
[CreateAssetMenu(fileName = "Player", menuName = "Player/Player", order = 0)]
|
||||
public class Player : ScriptableObject
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Marvin Schneider
|
||||
[CreateAssetMenu(fileName = "Weapon", menuName = "Weapon/Weapon", order = 0)]
|
||||
public class Weapon : ScriptableObject
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
//Ben Keller
|
||||
public class BulletScript : MonoBehaviour
|
||||
{
|
||||
private Vector3 mousePos;
|
||||
@@ -10,7 +11,6 @@ public class BulletScript : MonoBehaviour
|
||||
public float force;
|
||||
|
||||
public Weapon weapon;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
mainCamera = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
|
||||
|
Reference in New Issue
Block a user