Commit 68d76fe9 authored by Unknown's avatar Unknown

MovingPlattform / Spikes / Life

Funktionierende bewegbare Plattformen. Spikes die Leben vermindern und Life Script.
parent 55841b07
fileFormatVersion: 2
guid: 34373513566794d7087bff3c16ae2283
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &7475904797663268140
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7475904797663268136}
- component: {fileID: 7475904797663268143}
- component: {fileID: 7475904797663268142}
- component: {fileID: 7475904797663268141}
m_Layer: 9
m_Name: Plattform
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7475904797663268136
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475904797663268140}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 0.2, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &7475904797663268143
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475904797663268140}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: d0cee4e8b659c5646ac1e205b88a3256, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!61 &7475904797663268142
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475904797663268140}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &7475904797663268141
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7475904797663268140}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 380748855358446f380bc8c3c2ba54f1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Points:
- {x: -5, y: 0}
- {x: 0, y: 0}
m_Speed: 1
m_Wait: 2
m_MoveingByTouching: 0
m_Loop: 0
fileFormatVersion: 2
guid: 37ef3ab8efaf14862b2beb67c30828d0
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &3962879857309384166
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3962879857309384162}
- component: {fileID: 3962879857309384165}
- component: {fileID: 3962879857309384164}
- component: {fileID: 3962879857309384167}
m_Layer: 0
m_Name: Spikes
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3962879857309384162
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3962879857309384166}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.69, y: 0.29, z: 0}
m_LocalScale: {x: 0.5, y: 0.5, z: 0.5}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &3962879857309384165
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3962879857309384166}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: d0cee4e8b659c5646ac1e205b88a3256, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!61 &3962879857309384164
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3962879857309384166}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0.5, y: 0.5}
oldSize: {x: 1, y: 1}
newSize: {x: 1, y: 1}
adaptiveTilingThreshold: 0.5
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &3962879857309384167
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3962879857309384166}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d9a80b0c27701416b9182067ee42d48b, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Damage: 1
fileFormatVersion: 2
guid: 5ab2931e604d74039ab392b8189d5cbc
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof (BoxCollider2D))]
public class MovingPlattform : MonoBehaviour {
public List<Vector2> m_Points;
[SerializeField] private float m_Speed = 0.3f; //plattform geschwindigkeit
[SerializeField] private float m_Wait = 2f; //zeit in Sekunden wie lange die Plattform wartet
[SerializeField] private bool m_MoveingByTouching = false; //plattform bewegt sich nur bei Spieler Kontakt
[SerializeField] private bool m_Loop = false; //Bool zur festlegung ob plattform sich loopen soll
private bool isMoving = false; //Bool zu Checken ob Plattform sich bewegt kann auch genutzt werden um festzustellen ob die Coroutine Move(Vector2 a, Vector2 b) läuft
private bool isFacingForward = true; //sagt aus in welche Richtung sich die Plattform bewegt
private int isAt = 0; //Index an welcher stelle sich die Plattform in der List m_Points befindet
void Awake () {
SetStart (0);
}
void Update () {
if (m_Points.Count <= 1) return;
if (isMoving) return;
if (!m_MoveingByTouching)
Patrol ();
}
//Setze die Startposition der Plattform.
public void SetStart (int index) {
if (index >= 0 && index < m_Points.Count) {
this.isAt = index;
transform.position = m_Points[isAt];
}
}
//entscheidet ob die Plattformpatrolie läuft in einer Schleife oder die Plattform bewegt sich vor und zurück
private void Patrol () {
if (!m_Loop) {
//Controls movement back an forth
if (isFacingForward) {
MoveForward ();
} else {
MoveBackward ();
}
} else {
//Loops plattform motion forward. Can be Backwards
MoveForward ();
}
}
private void MoveForward () {
//wenn
if ((isAt + 1) < m_Points.Count) {
//normale vor und zurück bewegung
StartCoroutine (Move (m_Points[isAt], m_Points[isAt + 1]));
isAt++;
} else if ((isAt + 1) >= m_Points.Count && m_Loop) {
//Loop sprung der Plattform
StartCoroutine (Move (m_Points[isAt], m_Points[0]));
isAt = 0;
} else {
//setzten in welche richtung die Plattform sich bewegt
isFacingForward = false;
}
}
//selbe wie bei MoveForward nur Backwards
private void MoveBackward () {
if ((isAt - 1) >= 0) {
StartCoroutine (Move (m_Points[isAt], m_Points[isAt - 1]));
isAt--;
} else if ((isAt - 1) < 0 && m_Loop) {
StartCoroutine (Move (m_Points[isAt], m_Points[m_Points.Count - 1]));
isAt = m_Points.Count - 1;
} else {
isFacingForward = true;
}
}
//Coroutine zur bewegung der Plattform
private IEnumerator Move (Vector2 a, Vector2 b) {
isMoving = true;
for (float i = 0; i <= 1f; i += (m_Speed * Time.deltaTime)) {
transform.position = Vector2.Lerp (a, b, i);
yield return new WaitForEndOfFrame ();
}
yield return new WaitForSeconds (m_Wait);
isMoving = false;
}
//CollisionEnter mit Spieler kann um Gegner erweitert werden
void OnCollisionEnter2D (Collision2D col2D) {
if (col2D.transform.gameObject.tag.Equals ("Player")) {
//Setzt parent object des Spielers zu dieser Plattform somit wird die transformation der Plattform auf den Spieler Übertragen
col2D.transform.SetParent (gameObject.transform);
if (m_MoveingByTouching)
Patrol ();
}
}
//CollisionExit mit Spieler kann um Gegner erweitert werden
void OnCollisionExit2D (Collision2D col2D) {
if (col2D.transform.gameObject.tag.Equals ("Player")) {
//Sets Spieler Parent zu niemand
col2D.transform.SetParent (null);
}
}
void OnDrawGizmosSelected () {
if (m_Points != null) {
for (int i = 0; i < m_Points.Count; i++) {
Gizmos.color = Color.green;
Gizmos.DrawSphere (m_Points[i], 0.1f);
Gizmos.color = Color.blue;
if (i + 1 < m_Points.Count) {
Gizmos.DrawLine (m_Points[i], m_Points[i + 1]);
} else if (i + 1 >= m_Points.Count && m_Loop) {
Gizmos.DrawLine (m_Points[i], m_Points[0]);
}
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 380748855358446f380bc8c3c2ba54f1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent (typeof (BoxCollider2D))]
public class Spikes : MonoBehaviour {
[SerializeField] private int m_Damage = 1;
void OnCollisionEnter2D(Collision2D col2D){
if(col2D.transform.gameObject.tag.Equals("Player")){
Life l = col2D.transform.GetComponent<Life>();
l.Damage(m_Damage);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: d9a80b0c27701416b9182067ee42d48b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Life : MonoBehaviour {
[SerializeField] private int m_MaxLife = 1;
private int currentLife;
void Awake(){
currentLife = m_MaxLife;
}
public void Damage(int amount){
currentLife -= amount;
if(currentLife <= 0){
currentLife = 0;
Death();
}
}
public bool Heal(int amount){
if(currentLife == m_MaxLife){
return false;
}else{
Mathf.Clamp(currentLife += amount, 0, m_MaxLife);
return true;
}
}
public void Death(){
//Reset
Destroy(gameObject);
Debug.Log("Death");
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 3c0ce2eb523274b6fa61fccbf0227d85
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -54,7 +54,6 @@ public class MovementController : MonoBehaviour {
m_TempJumpCount = m_MaxJumpCount;
if (!wasGrounded)
OnLandEvent.Invoke ();
Debug.Log(m_Grounded);
}
}
}
......
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