Commit 6d4e1f34 authored by Sebastian Frey's avatar Sebastian Frey

AttackScripts geändert; Charges werden jetzt korrekt angepasst

parent 8fa23c3e
......@@ -40,15 +40,14 @@ GameObject:
m_Component:
- component: {fileID: 52145075018362285}
- component: {fileID: 52145075018362290}
- component: {fileID: 52145075018362284}
- component: {fileID: 2596175625849265254}
- component: {fileID: 2055293003418080559}
- component: {fileID: 52145075018362291}
- component: {fileID: 52145075018362284}
- component: {fileID: 352228602}
- component: {fileID: 352228603}
- component: {fileID: 352228604}
- component: {fileID: 352228605}
- component: {fileID: 352228606}
- component: {fileID: 2596175625849265254}
m_Layer: 10
m_Name: Player
m_TagString: Player
......@@ -119,6 +118,43 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!50 &52145075018362284
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 1
m_Constraints: 4
--- !u!70 &2596175625849265254
CapsuleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.05, y: -0.3}
m_Size: {x: 1.06, y: 1.46}
m_Direction: 0
--- !u!114 &2055293003418080559
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -175,27 +211,6 @@ MonoBehaviour:
m_Calls: []
m_TypeName: UnityEngine.Events.UnityEvent, UnityEngine.CoreModule, Version=0.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!50 &52145075018362284
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 1
m_Constraints: 4
--- !u!114 &352228602
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -209,8 +224,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
state: {fileID: 11400000, guid: c5777bcc7b64ce24c9bd65d2c4b7c639, type: 2}
onElementInfused: {fileID: 11400000, guid: 7e5b80a8353af1846a878c3a997bdb4a, type: 2}
onChargeChange: {fileID: 11400000, guid: 6ec6544f645a9d1458383b111fcaf8b6, type: 2}
--- !u!114 &352228603
MonoBehaviour:
m_ObjectHideFlags: 0
......@@ -218,7 +231,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: adc21094da13d8649a490855a137565f, type: 3}
m_Name:
......@@ -237,7 +250,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ad90db0185377664288543ce4696c6b8, type: 3}
m_Name:
......@@ -252,7 +265,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 83eb4399ff535ee4cbc76de3b8a32e46, type: 3}
m_Name:
......@@ -263,37 +276,3 @@ MonoBehaviour:
attackSpeed: 1
shotSpawn: {fileID: 2139239323}
fireBall: {fileID: 1870586037468468, guid: e5f7d8895a3df6547bca926919077d19, type: 3}
--- !u!114 &352228606
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5a8392b2d467dfc428ede6cd785337f2, type: 3}
m_Name:
m_EditorClassIdentifier:
weight: 0
isPerformingAction: 0
windAttack: {fileID: 0}
Cooldown: 0
attackRange: 0
firePower: 0
--- !u!70 &2596175625849265254
CapsuleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 52145075018362288}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.05, y: -0.3}
m_Size: {x: 1.06, y: 1.46}
m_Direction: 0
......@@ -5,7 +5,7 @@ namespace _Game.Scripts.Player.PlayerAttacks.Earth
{
public class PlayerEarthAttack : MonoBehaviour
{
private float nextFire;
private float _nextFire;
public float cooldown;
public float massIncrease;
public bool isStomping;
......@@ -21,42 +21,30 @@ namespace _Game.Scripts.Player.PlayerAttacks.Earth
{
controller = GetComponentInParent<MovementController>();
contactFilter2D.SetLayerMask(whatIsDestroyable);
_nextFire = 0;
_ready = true;
_activated = false;
}
private void Update()
{
_ready = Time.time > _nextFire;
}
public bool Attack()
{
if (_ready)
{
_activated = true;
StartCoroutine(Fire());
_ready = false;
_nextFire = Time.time + cooldown;
return true;
}
return _ready;
}
// Update is called once per frame
void Update()
{
_ready = Time.time > nextFire;
if (!_activated) return;
print("Fire_Attack");
nextFire = Time.time + cooldown;
StartCoroutine(fire());
_activated = false;
//if (Input.GetButtonDown("Fire1") && Time.time > nextFire && !controller.Grounded)
//{
// nextFire = Time.time + Cooldown;
// StartCoroutine(fire());
//}
return false;
}
IEnumerator fire()
IEnumerator Fire()
{
controller.GetComponentInParent<Rigidbody2D>().gravityScale *= massIncrease;
isStomping = true;
......
fileFormatVersion: 2
guid: 87867fa499c44294f8c224ff00e99e73
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace _Game.Scripts.Player.PlayerAttacks.Fire
{
public class PlayerFireProjectile : MonoBehaviour
{
public double damage;
public GameObject nearestPlayer;
/// <summary>
/// Bisher werden die Shots nach einer Sekunde auf inactive gesetzt
/// hier muss noch was mit Collidern eingefügt werden um
/// auf Zusammenstöße reagieren zu können, damit der Shot dann
/// auf inactive gesetzt wird
/// </summary>
public float destroyTime = 1f;
/// <summary>
/// Wenn das Geschoss auf active gesetzt wird, wird nach 2 Sekunden
/// die Destroy Methode aufgerufen
/// </summary>
private void OnEnable()
{
Invoke("Destroy", destroyTime);
}
/// <summary>
/// Setzt das Geschoss auf 'inactive'
/// </summary>
private void Destroy()
{
Destroy(gameObject);
}
/// <summary>
/// Beim Zusammenstoß mit einem anderen GameObject
/// </summary>
/// <param name="collision"></param>
private void OnTriggerEnter2D(Collider2D target)
{
//if (target.CompareTag("Enemy"))
//{
// return;
//}
//Destroy();
}
}
}
fileFormatVersion: 2
guid: 995e9971f4a3eda4da6ce08b6fdffd42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -3,7 +3,7 @@ using UnityEngine;
namespace _Game.Scripts.Player.PlayerAttacks.Fire
{
public class PlayerFireAttack : MonoBehaviour
public class Player_FireAttack : MonoBehaviour
{
private float _nextFire;
public float cooldown;
......@@ -12,32 +12,41 @@ namespace _Game.Scripts.Player.PlayerAttacks.Fire
public float attackSpeed;
public Transform shotSpawn;
public GameObject elementalAttack;
public GameObject fireBall;
private Rigidbody2D _body;
private Rigidbody2D body;
private bool _ready;
private void Start()
{
_nextFire = 0;
_ready = true;
}
private void Update()
{
if (!Input.GetButtonDown("Fire1") || !(Time.time > _nextFire)) return;
_ready = Time.time > _nextFire;
}
Debug.Log("Fire_Attack");
_nextFire = Time.time + cooldown;
public bool Attack()
{
if (_ready)
{
StartCoroutine(Fire());
_ready = false;
_nextFire = Time.time + cooldown;
return true;
}
StartCoroutine(Fire());
return false;
}
private IEnumerator Fire()
IEnumerator Fire()
{
for (var i = 0; i < volleySize; i++)
for (int i = 0; i < volleySize; i++)
{
var position = shotSpawn.position;
var projectile = Instantiate(elementalAttack, position, shotSpawn.rotation);
var direction = position - transform.position;
GameObject projectile = Instantiate(fireBall, shotSpawn.position, shotSpawn.rotation);
Vector3 direction = shotSpawn.position - transform.position;
projectile.GetComponent<Rigidbody2D>().velocity = direction * launchPower;
yield return new WaitForSeconds(attackSpeed);
}
......
using UnityEngine;
namespace _Game.Scripts.Player.PlayerAttacks.Fire
{
public class Player_FireProjectile : MonoBehaviour
{
public double damage;
public GameObject nearestPlayer;
public float destroyTime = 1f;
void OnEnable()
{
Invoke("Destroy", destroyTime);
}
void Destroy()
{
Destroy(gameObject);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.layer == LayerMask.NameToLayer("Enemy"))
{
if (collision.gameObject.CompareTag("Water"))
{
collision.gameObject.GetComponent<Life>().Damage(1);
Destroy();
}
}
else if (collision.gameObject.CompareTag("DestroyableByFire"))
{
Destroy();
}
}
}
}
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class Player_FireAttack : MonoBehaviour
{
private float nextFire;
public float cooldown;
public int volleySize;
public float launchPower;
public float attackSpeed;
public Transform shotSpawn;
public GameObject fireBall;
private Rigidbody2D body;
private bool _ready;
private bool _activated;
private void Start()
{
nextFire = 0;
_ready = true;
_activated = false;
}
private void Update()
{
_ready = Time.time > nextFire;
if (!_activated) return;
print("Fire_Attack");
nextFire = Time.time + cooldown;
StartCoroutine(fire());
_activated = false;
//if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
//{
// nextFire = Time.time + Cooldown;
// StartCoroutine(fire());
//}
}
public bool Attack()
{
if (_ready)
{
_activated = true;
}
return _ready;
}
IEnumerator fire()
{
for (int i = 0; i < volleySize; i++)
{
GameObject projectile = Instantiate(fireBall, shotSpawn.position, shotSpawn.rotation);
Vector3 direction = shotSpawn.position - transform.position;
projectile.GetComponent<Rigidbody2D>().velocity = direction * launchPower;
yield return new WaitForSeconds(attackSpeed);
}
}
}
using UnityEngine;
public class Player_FireProjectile : MonoBehaviour
{
public double damage;
public GameObject nearestPlayer;
public float destroyTime = 1f;
void OnEnable()
{
Invoke("Destroy", destroyTime);
}
void Destroy()
{
Destroy(gameObject);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.layer == LayerMask.NameToLayer("Enemy"))
{
if (collision.gameObject.CompareTag("Water"))
{
collision.gameObject.GetComponent<Life>().Damage(1);
Destroy();
}
}
else if (collision.gameObject.CompareTag("DestroyableByFire"))
{
Destroy();
}
}
}
......@@ -17,37 +17,29 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
public GameObject elementalAttack;
private bool _ready;
private bool _activated;
private void Start()
{
_nextFire = 0.0f;
_ready = true;
_activated = false;
}
private void Update()
{
_ready = Time.time > _nextFire;
if (!_activated) return;
print("Water_Attack");
_nextFire = Time.time + cooldown;
StartCoroutine(Fire());
_activated = false;
}
public bool Attack()
{
if (_ready)
{
_activated = true;
StartCoroutine(Fire());
_ready = false;
_nextFire = Time.time + cooldown;
return true;
}
return _ready;
return false;
}
private IEnumerator Fire()
......
using System;
using UnityEngine;
using _Game.Scripts.Elements;
using _Game.Scripts.Player.PlayerAttacks.Air;
using _Game.Scripts.Player.PlayerAttacks.Earth;
using _Game.Scripts.Player.PlayerAttacks.Fire;
using _Game.Scripts.Player.PlayerAttacks.Water;
......@@ -9,7 +8,7 @@ using _Game.Scripts.Scriptable_Object;
namespace _Game.Scripts.Player
{
[RequireComponent(typeof(PlayerAirAttack), typeof(Player_FireAttack))]
[RequireComponent(typeof(Player_FireAttack))]
[RequireComponent(typeof(PlayerEarthAttack), typeof(PlayerWaterAttack))]
public class PlayerInteract : MonoBehaviour
......@@ -19,9 +18,6 @@ namespace _Game.Scripts.Player
[SerializeField] private PlayerState state;
[SerializeField] private ElementGameEventListener onElementChanged;
private PlayerAirAttack _airAttack;
private PlayerEarthAttack _earthAttack;
private Player_FireAttack _fireAttack;
private PlayerWaterAttack _waterAttack;
......@@ -30,19 +26,16 @@ namespace _Game.Scripts.Player
private void Start()
{
_airAttack = this.gameObject.GetComponent<PlayerAirAttack>();
_earthAttack = this.gameObject.GetComponent<PlayerEarthAttack>();
_fireAttack = this.gameObject.GetComponent<Player_FireAttack>();
_waterAttack = this.gameObject.GetComponent<PlayerWaterAttack>();
_controller = this.gameObject.GetComponent<MovementController>();
state.UpdateElement(InfusedElement.None);
_airAttack.enabled = false;
_earthAttack.enabled = false;
_fireAttack.enabled = false;
_waterAttack.enabled = false;
// _controller.SetMovementParameters(state.GetCurrentMovementState());
//_controller.SetMovementParameters(state.GetCurrentMovementState());
}
private void Update()
......@@ -51,13 +44,6 @@ namespace _Game.Scripts.Player
{
switch (state.GetCurrentElement())
{
//case InfusedElement.Air:
// if(_waterAttack.Attack())
// {
// state.ChangeCharges(-1);
// onChargeChange.Raise();
// }
//break;
case InfusedElement.Earth:
if (_earthAttack.Attack())
{
......@@ -78,8 +64,6 @@ namespace _Game.Scripts.Player
break;
case InfusedElement.None:
break;
case InfusedElement.Air:
break;
default:
throw new ArgumentOutOfRangeException();