Commit 86fcd798 authored by Sebastian Frey's avatar Sebastian Frey
Browse files

charges für das Element hinzugefügt

parent 65c57136
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e69f8fd89dc139a49b0d4d154f5497dd, type: 3}
m_Name: ChargeGameEvent
m_EditorClassIdentifier:
fileFormatVersion: 2
guid: 6ec6544f645a9d1458383b111fcaf8b6
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
...@@ -12,6 +12,7 @@ MonoBehaviour: ...@@ -12,6 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 353b156b7c59b1c45a8767d7500b31fb, type: 3} m_Script: {fileID: 11500000, guid: 353b156b7c59b1c45a8767d7500b31fb, type: 3}
m_Name: PlayerState m_Name: PlayerState
m_EditorClassIdentifier: m_EditorClassIdentifier:
currentInfusedElement: 2
currentMoveState: currentMoveState:
jumpForce: 0 jumpForce: 0
smoothing: 0 smoothing: 0
...@@ -21,10 +22,4 @@ MonoBehaviour: ...@@ -21,10 +22,4 @@ MonoBehaviour:
mass: 0 mass: 0
gravity: 0 gravity: 0
movementStates: {fileID: 11400000, guid: c757aad6925b37a46b916f609fa9012b, type: 2} movementStates: {fileID: 11400000, guid: c757aad6925b37a46b916f609fa9012b, type: 2}
currentJumpForce: 0 charges: 4
currentSmoothing: 0
currentAirControl: 0
currentMoveSpeed: 0
currentMaxJumpCount: 0
currentMass: 0
currentGravity: 0
...@@ -98,7 +98,7 @@ Rigidbody2D: ...@@ -98,7 +98,7 @@ Rigidbody2D:
m_LinearDrag: 0 m_LinearDrag: 0
m_AngularDrag: 0.05 m_AngularDrag: 0.05
m_GravityScale: 1 m_GravityScale: 1
m_Material: {fileID: 0} m_Material: {fileID: 6200000, guid: 58a62fd7692ebb24bbefaaac19fed6fc, type: 2}
m_Interpolate: 0 m_Interpolate: 0
m_SleepingMode: 1 m_SleepingMode: 1
m_CollisionDetection: 0 m_CollisionDetection: 0
......
...@@ -38,7 +38,7 @@ RenderSettings: ...@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0} m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} m_IndirectSpecularColor: {r: 0.18028334, g: 0.22571328, b: 0.3069217, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
...@@ -1050,6 +1050,7 @@ MonoBehaviour: ...@@ -1050,6 +1050,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
state: {fileID: 11400000, guid: c5777bcc7b64ce24c9bd65d2c4b7c639, type: 2} state: {fileID: 11400000, guid: c5777bcc7b64ce24c9bd65d2c4b7c639, type: 2}
onElementInfused: {fileID: 11400000, guid: 7e5b80a8353af1846a878c3a997bdb4a, type: 2} onElementInfused: {fileID: 11400000, guid: 7e5b80a8353af1846a878c3a997bdb4a, type: 2}
onChargeChange: {fileID: 11400000, guid: 6ec6544f645a9d1458383b111fcaf8b6, type: 2}
--- !u!4 &1876157337 stripped --- !u!4 &1876157337 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 52145075018362285, guid: 2e3528907311e438dab0d393127aa332, m_CorrespondingSourceObject: {fileID: 52145075018362285, guid: 2e3528907311e438dab0d393127aa332,
......
...@@ -16,21 +16,38 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water ...@@ -16,21 +16,38 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
public Transform shotSpawn; public Transform shotSpawn;
public GameObject elementalAttack; public GameObject elementalAttack;
private bool _ready;
private bool _activated;
private void Start() private void Start()
{ {
_nextFire = 0.0f; _nextFire = 0.0f;
_ready = true;
_activated = false;
} }
private void Update() private void Update()
{ {
if (!Input.GetButtonDown("Fire1") || !(Time.time > _nextFire)) return; _ready = Time.time > _nextFire;
if (!_activated) return;
Debug.Log("Water_Attack"); print("Water_Attack");
_nextFire = _nextFire + cooldown; _nextFire = Time.time + cooldown;
StartCoroutine(Fire()); StartCoroutine(Fire());
} }
public bool Attack()
{
if (_ready)
{
_activated = true;
}
return _ready;
}
private IEnumerator Fire() private IEnumerator Fire()
{ {
for (var i = 0; i < volleySize; i++) for (var i = 0; i < volleySize; i++)
...@@ -47,6 +64,8 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water ...@@ -47,6 +64,8 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
projectile.GetComponent<Rigidbody2D>().velocity = direction * launchPower; projectile.GetComponent<Rigidbody2D>().velocity = direction * launchPower;
yield return new WaitForSeconds(attackSpeed); yield return new WaitForSeconds(attackSpeed);
} }
_activated = false;
} }
} }
} }
...@@ -24,14 +24,18 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water ...@@ -24,14 +24,18 @@ namespace _Game.Scripts.Player.PlayerAttacks.Water
private void Update() private void Update()
{ {
_deltaTime = (Time.time - _startTime) / destroyTime; _deltaTime = (Time.time - _startTime) / destroyTime;
print("t: " + _deltaTime); if (_deltaTime >= 0.8f)
_newScaleFactor = _deltaTime * (1 - _deltaTime) * (1 - _deltaTime) / 0.1481481481481f; {
print("f(" + _deltaTime + ")= " + _newScaleFactor); _newScaleFactor = (1 - _deltaTime) * 5.0f;
}
else
{
_newScaleFactor = 1.0f;
}
_newScaleVector = new Vector3(_newScaleFactor, _newScaleFactor, 0.0f); _newScaleVector = new Vector3(_newScaleFactor * _startingScale.x, _newScaleFactor * _startingScale.y, 0.0f);
this.gameObject.transform.localScale = _newScaleVector; this.gameObject.transform.localScale = _newScaleVector;
_rigidbody2D.velocity = _startingVelocity * (1 - (1 - _deltaTime) * (1 - _deltaTime));
} }
private void OnEnable() private void OnEnable()
......
using UnityEngine; using System;
using UnityEngine;
using _Game.Scripts.Elements; using _Game.Scripts.Elements;
using _Game.Scripts.Player.PlayerAttacks.Air; using _Game.Scripts.Player.PlayerAttacks.Air;
using _Game.Scripts.Player.PlayerAttacks.Earth; using _Game.Scripts.Player.PlayerAttacks.Earth;
...@@ -10,7 +11,6 @@ namespace _Game.Scripts.Player ...@@ -10,7 +11,6 @@ namespace _Game.Scripts.Player
{ {
public class PlayerInteract : MonoBehaviour public class PlayerInteract : MonoBehaviour
{ {
private GameObject _currentObject; private GameObject _currentObject;
private InteractionObject _targetScript; private InteractionObject _targetScript;
...@@ -18,6 +18,8 @@ namespace _Game.Scripts.Player ...@@ -18,6 +18,8 @@ namespace _Game.Scripts.Player
[SerializeField] private ElementGameEvent onElementInfused; [SerializeField] private ElementGameEvent onElementInfused;
[SerializeField] private ChargeGameEvent onChargeChange;
private PlayerAirAttack _airAttack; private PlayerAirAttack _airAttack;
private PlayerEarthAttack _earthAttack; private PlayerEarthAttack _earthAttack;
private Player_FireAttack _fireAttack; private Player_FireAttack _fireAttack;
...@@ -33,13 +35,55 @@ namespace _Game.Scripts.Player ...@@ -33,13 +35,55 @@ namespace _Game.Scripts.Player
private void Update() private void Update()
{ {
if (Input.GetButtonDown("Fire1"))
{
switch (state.GetCurrentElement())
{
case InfusedElement.Air:
// if(_waterAttack.Attack())
// {
// state.ChangeCharges(-1);
// onChargeChange.Raise();
// }
break;
case InfusedElement.Earth:
// if(_waterAttack.Attack())
// {
// state.ChangeCharges(-1);
// onChargeChange.Raise();
// }
break;
case InfusedElement.Fire:
// if(_waterAttack.Attack())
// {
// state.ChangeCharges(-1);
// onChargeChange.Raise();
// }
// break;
case InfusedElement.Water:
print("done");
if(_waterAttack.Attack())
{
state.ChangeCharges(-1);
onChargeChange.Raise();
}
break;
case InfusedElement.None:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
if (!Input.GetButtonDown("Interact") || !_currentObject) return; if (!Input.GetButtonDown("Interact") || !_currentObject) return;
switch (_currentObject.tag) switch (_currentObject.tag)
{ {
case "Air": case "Air":
state.UpdateElement(InfusedElement.Air); state.UpdateElement(InfusedElement.Air);
state.ChangeCharges(3);
onElementInfused.Raise(InfusedElement.Air); onElementInfused.Raise(InfusedElement.Air);
onChargeChange.Raise();
_airAttack.enabled = true; _airAttack.enabled = true;
_earthAttack.enabled = false; _earthAttack.enabled = false;
_fireAttack.enabled = false; _fireAttack.enabled = false;
...@@ -47,7 +91,9 @@ namespace _Game.Scripts.Player ...@@ -47,7 +91,9 @@ namespace _Game.Scripts.Player
break; break;
case "Earth": case "Earth":
state.UpdateElement(InfusedElement.Earth); state.UpdateElement(InfusedElement.Earth);
state.ChangeCharges(3);
onElementInfused.Raise(InfusedElement.Earth); onElementInfused.Raise(InfusedElement.Earth);
onChargeChange.Raise();
_airAttack.enabled = false; _airAttack.enabled = false;
_earthAttack.enabled = true; _earthAttack.enabled = true;
_fireAttack.enabled = false; _fireAttack.enabled = false;
...@@ -55,7 +101,9 @@ namespace _Game.Scripts.Player ...@@ -55,7 +101,9 @@ namespace _Game.Scripts.Player
break; break;
case "Fire": case "Fire":
state.UpdateElement(InfusedElement.Fire); state.UpdateElement(InfusedElement.Fire);
state.ChangeCharges(3);
onElementInfused.Raise(InfusedElement.Fire); onElementInfused.Raise(InfusedElement.Fire);
onChargeChange.Raise();
_airAttack.enabled = false; _airAttack.enabled = false;
_earthAttack.enabled = false; _earthAttack.enabled = false;
_fireAttack.enabled = true; _fireAttack.enabled = true;
...@@ -63,7 +111,9 @@ namespace _Game.Scripts.Player ...@@ -63,7 +111,9 @@ namespace _Game.Scripts.Player
break; break;
case "Water": case "Water":
state.UpdateElement(InfusedElement.Water); state.UpdateElement(InfusedElement.Water);
state.ChangeCharges(3);
onElementInfused.Raise(InfusedElement.Water); onElementInfused.Raise(InfusedElement.Water);
onChargeChange.Raise();
_airAttack.enabled = false; _airAttack.enabled = false;
_earthAttack.enabled = false; _earthAttack.enabled = false;
_fireAttack.enabled = false; _fireAttack.enabled = false;
...@@ -71,7 +121,9 @@ namespace _Game.Scripts.Player ...@@ -71,7 +121,9 @@ namespace _Game.Scripts.Player
break; break;
default: default:
state.UpdateElement(InfusedElement.None); state.UpdateElement(InfusedElement.None);
state.ChangeCharges(3);
onElementInfused.Raise(InfusedElement.None); onElementInfused.Raise(InfusedElement.None);
onChargeChange.Raise();
_airAttack.enabled = false; _airAttack.enabled = false;
_earthAttack.enabled = false; _earthAttack.enabled = false;
_fireAttack.enabled = false; _fireAttack.enabled = false;
...@@ -86,7 +138,7 @@ namespace _Game.Scripts.Player ...@@ -86,7 +138,7 @@ namespace _Game.Scripts.Player
{ {
if (other.gameObject.layer != LayerMask.NameToLayer("Elements")) return; if (other.gameObject.layer != LayerMask.NameToLayer("Elements")) return;
Debug.Log("Entered Collider of " + other.name); print("Entered Collider of " + other.name);
_currentObject = other.gameObject; _currentObject = other.gameObject;
_targetScript = _currentObject.GetComponent<InteractionObject>(); _targetScript = _currentObject.GetComponent<InteractionObject>();
} }
...@@ -96,7 +148,7 @@ namespace _Game.Scripts.Player ...@@ -96,7 +148,7 @@ namespace _Game.Scripts.Player
if (other.gameObject.layer != LayerMask.NameToLayer("Elements")) return; if (other.gameObject.layer != LayerMask.NameToLayer("Elements")) return;
if (other.gameObject != _currentObject) return; if (other.gameObject != _currentObject) return;
Debug.Log("Exited Collider of " + other.name); print("Exited Collider of " + other.name);
_currentObject = null; _currentObject = null;
_targetScript = null; _targetScript = null;
} }
......
using System.Collections.Generic;
using UnityEngine;
namespace _Game.Scripts.Scriptable_Object
{
[CreateAssetMenu(fileName = "New Charge Game Event", menuName = "Charge Game Event", order = 53)]
public class ChargeGameEvent : ScriptableObject
{
private readonly List<ChargeGameEventListener> _listeners = new List<ChargeGameEventListener>();
public void Raise()
{
for (var i = _listeners.Count - 1; i >= 0; i--)
{
_listeners[i].OnEventRaised();
}
}
public void RegisterListener(ChargeGameEventListener listener)
{
_listeners.Add(listener);
}
public void UnregisterListener(ChargeGameEventListener listener)
{
_listeners.Remove(listener);
}
}
}
fileFormatVersion: 2
guid: e69f8fd89dc139a49b0d4d154f5497dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.Events;
namespace _Game.Scripts.Scriptable_Object
{
public class ChargeGameEventListener : MonoBehaviour
{
[SerializeField] private ChargeGameEvent gameEvent;
[SerializeField] private UnityEvent response;
private void OnEnable()
{
gameEvent.RegisterListener(this);
}
private void OnDisable()
{
gameEvent.UnregisterListener(this);
}
public void OnEventRaised()
{
response.Invoke();
}
}
}
fileFormatVersion: 2
guid: cae13dfa42160034cbe0b3a99bd73368
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -5,7 +5,7 @@ using UnityEngine.Serialization; ...@@ -5,7 +5,7 @@ using UnityEngine.Serialization;
namespace _Game.Scripts.Scriptable_Object namespace _Game.Scripts.Scriptable_Object
{ {
[CreateAssetMenu(fileName = "New Movement State", menuName = "Movement State", order = 53)] [CreateAssetMenu(fileName = "New Movement State", menuName = "Movement State", order = 54)]
public class MovementStates : ScriptableObject public class MovementStates : ScriptableObject
{ {
public MovementState airMoveState; public MovementState airMoveState;
......
...@@ -11,22 +11,25 @@ namespace _Game.Scripts.Scriptable_Object ...@@ -11,22 +11,25 @@ namespace _Game.Scripts.Scriptable_Object
[CreateAssetMenu(fileName = "New Player State", menuName = "Player State", order = 51)] [CreateAssetMenu(fileName = "New Player State", menuName = "Player State", order = 51)]
public class PlayerState : ScriptableObject public class PlayerState : ScriptableObject
{ {
//[SerializeField] private InfusedElement currentInfusedElement; [SerializeField] private InfusedElement currentInfusedElement;
[SerializeField] private MovementState currentMoveState; [SerializeField] private MovementState currentMoveState;
[SerializeField] private MovementStates movementStates; [SerializeField] private MovementStates movementStates;
[SerializeField] private float currentJumpForce; [SerializeField][Range(0, 5)] private int charges;
[SerializeField] private float currentSmoothing;
[SerializeField] private bool currentAirControl; // [SerializeField] private float currentJumpForce;
[SerializeField] private float currentMoveSpeed; // [SerializeField] private float currentSmoothing;
[SerializeField] private int currentMaxJumpCount; // [SerializeField] private bool currentAirControl;
[SerializeField] private float currentMass; // [SerializeField] private float currentMoveSpeed;
[SerializeField] private float currentGravity; // [SerializeField] private int currentMaxJumpCount;
// [SerializeField] private float currentMass;
// [SerializeField] private float currentGravity;
public void UpdateElement(InfusedElement newElement) public void UpdateElement(InfusedElement newElement)
{ {
//currentInfusedElement = newElement; currentInfusedElement = newElement;
currentMoveState = movementStates.GetMovementState(newElement); currentMoveState = movementStates.GetMovementState(newElement);
} }
...@@ -34,6 +37,32 @@ namespace _Game.Scripts.Scriptable_Object ...@@ -34,6 +37,32 @@ namespace _Game.Scripts.Scriptable_Object
{ {
return currentMoveState; return currentMoveState;
} }
public void ChangeCharges(int amount)
{
if ((charges + amount) > 5)
{
charges = 5;
} else if ((charges + amount) <= 0)
{
charges = 0;
currentInfusedElement = InfusedElement.None;
}
else
{
charges += amount;
}
}
public int GetCharges()
{
return charges;
}
public InfusedElement GetCurrentElement()
{
return currentInfusedElement;
}
} }
public enum InfusedElement public enum InfusedElement
......
Markdown is supported
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