Commit 461a2bcb authored by Max's avatar Max
Browse files

changed crawler scripts to one general walkbehaviour script

parent 836732f4
......@@ -162,6 +162,26 @@ AnimatorStateMachine:
m_ExitPosition: {x: 870, y: 670, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 8415805674711102845}
--- !u!114 &-4336568722481481660
MonoBehaviour:
m_ObjectHideFlags: 1
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: 68a0d52f582cf814592a96a7672f0495, type: 3}
m_Name:
m_EditorClassIdentifier:
isIdle: 1
isWalkingRight: 1
alertDistance: 10
backToIdleDistance: 15
speed: 1
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!114 &-3648934846570529807
MonoBehaviour:
m_ObjectHideFlags: 1
......@@ -209,10 +229,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5b449e47ad214594dba87ebc6349d10d, type: 3}
m_Name:
m_EditorClassIdentifier:
player: {fileID: 0}
myTransform: {fileID: 0}
myPosition: {x: 0, y: 0, z: 0}
myWidth: 0
myHeight: 0
alertDistance: 5
idleSpeed: 2
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!1102 &-2126546418195010665
AnimatorState:
......@@ -228,7 +252,7 @@ AnimatorState:
- {fileID: -7665864225873023536}
- {fileID: -87046515038896864}
m_StateMachineBehaviours:
- {fileID: 4013138057911936102}
- {fileID: 5984990088884169840}
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
......@@ -243,6 +267,26 @@ AnimatorState:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!114 &-1742997513752910653
MonoBehaviour:
m_ObjectHideFlags: 1
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: 68a0d52f582cf814592a96a7672f0495, type: 3}
m_Name:
m_EditorClassIdentifier:
isIdle: 0
isWalkingRight: 0
alertDistance: 10
backToIdleDistance: 15
speed: 3
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!114 &-1015852849551215036
MonoBehaviour:
m_ObjectHideFlags: 1
......@@ -370,7 +414,7 @@ AnimatorState:
- {fileID: -647988718983959964}
- {fileID: -5435497801864865747}
m_StateMachineBehaviours:
- {fileID: 3943066035886356273}
- {fileID: -1742997513752910653}
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
......@@ -420,40 +464,6 @@ MonoBehaviour:
myTransform: {fileID: 0}
myWidth: 0
myHeight: 0
--- !u!114 &3943066035886356273
MonoBehaviour:
m_ObjectHideFlags: 1
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: 3ed5579b2c93ccc4ba486e834c814bed, type: 3}
m_Name:
m_EditorClassIdentifier:
backToIdleDistance: 10
movingSpeed: 4
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!114 &4013138057911936102
MonoBehaviour:
m_ObjectHideFlags: 1
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: fd26be7c230e87949ba1692847aeca90, type: 3}
m_Name:
m_EditorClassIdentifier:
backToIdleDistance: 10
movingSpeed: 4
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!1101 &4374640023923578731
AnimatorStateTransition:
m_ObjectHideFlags: 1
......@@ -528,8 +538,51 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 68a0d52f582cf814592a96a7672f0495, type: 3}
m_Name:
m_EditorClassIdentifier:
isIdle: 0
isWalkingRight: 0
alertDistance: 5
idleSpeed: 2
backToIdleDistance: 0
speed: 0
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!114 &5984990088884169840
MonoBehaviour:
m_ObjectHideFlags: 1
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: 68a0d52f582cf814592a96a7672f0495, type: 3}
m_Name:
m_EditorClassIdentifier:
isIdle: 0
isWalkingRight: 1
alertDistance: 10
backToIdleDistance: 15
speed: 3
enemyMask:
serializedVersion: 2
m_Bits: 256
--- !u!114 &6291902074659076388
MonoBehaviour:
m_ObjectHideFlags: 1
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: 68a0d52f582cf814592a96a7672f0495, type: 3}
m_Name:
m_EditorClassIdentifier:
isIdle: 1
isWalkingRight: 0
alertDistance: 10
backToIdleDistance: 15
speed: 1
enemyMask:
serializedVersion: 2
m_Bits: 256
......@@ -547,7 +600,7 @@ AnimatorState:
- {fileID: -5742401130475968656}
- {fileID: 6883036299962769485}
m_StateMachineBehaviours:
- {fileID: 5578189745199563759}
- {fileID: 6291902074659076388}
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
......@@ -626,7 +679,7 @@ AnimatorState:
- {fileID: 4374640023923578731}
- {fileID: 5295866313451080789}
m_StateMachineBehaviours:
- {fileID: -3222830713410934465}
- {fileID: -4336568722481481660}
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &382294967272604784
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 382294967272604787}
- component: {fileID: 382294967272604786}
- component: {fileID: 382294967272604789}
m_Layer: 0
m_Name: Crawler
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &382294967272604787
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 382294967272604784}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -11, y: -12, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &382294967272604786
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 382294967272604784}
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: 1
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: 245e8e37213da124f85d810816c66bc4, 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!95 &382294967272604789
Animator:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 382294967272604784}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 771143dd21626c94dbf504ea3bc82c50, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
fileFormatVersion: 2
guid: 3ed5579b2c93ccc4ba486e834c814bed
MonoImporter:
guid: 96acf84506032df4a9606f94e545302d
PrefabImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -600,7 +600,7 @@ ParticleSystem:
m_PostInfinity: 2
m_RotationOrder: 4
randomizeRotationDirection: 0
maxNumParticles: 75
maxNumParticles: 50
size3D: 0
rotation3D: 0
gravityModifier:
......
......@@ -129,7 +129,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 131995713}
m_Layer: 0
m_Layer: 8
m_Name: Background
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -695,7 +695,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 473954089}
m_Layer: 0
m_Layer: 8
m_Name: Ground
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -947,7 +947,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 671354061}
m_Layer: 0
m_Layer: 8
m_Name: Walls
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -1801,105 +1801,12 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &1528782777
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1528782778}
- component: {fileID: 1528782779}
- component: {fileID: 1528782780}
m_Layer: 0
m_Name: Crawler
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1528782778
--- !u!4 &1528782778 stripped
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1528782777}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -11, y: -12, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1719407322}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &1528782779
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1528782777}
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: 1
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: 245e8e37213da124f85d810816c66bc4, 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!95 &1528782780
Animator:
serializedVersion: 3
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
m_PrefabInstance: {fileID: 382294966282181577}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1528782777}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: 771143dd21626c94dbf504ea3bc82c50, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0
--- !u!1 &1585612736
GameObject:
m_ObjectHideFlags: 0
......@@ -2099,7 +2006,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 1652412121}
m_Layer: 0
m_Layer: 8
m_Name: Ceiling
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -2679,6 +2586,75 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1001 &382294966282181577
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1719407322}
m_Modifications:
- target: {fileID: 382294967272604784, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_Name
value: Crawler
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalPosition.x
value: -11
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalPosition.y
value: -12
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 382294967272604787, guid: 96acf84506032df4a9606f94e545302d,
type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 96acf84506032df4a9606f94e545302d, type: 3}
--- !u!1001 &7591825400398959993
PrefabInstance:
m_ObjectHideFlags: 0
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CrawlerIdleRight : StateMachineBehaviour
{
//Referenz auf den Spieler
private GameObject player;
//Referenzen auf den Gegner
private Transform myTransform;
private Vector3 myPosition;
private float myWidth;
private float myHeight;
//benötigte Distanz um alarmiert zu werden
public float alertDistance;
//Geschwindigkeit wenn nicht alarmiert
public float idleSpeed;
//alle Ebenen, mit denen der Gegner kollidieren soll
public LayerMask enemyMask;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
player = GameObject.FindGameObjectWithTag("Player");
myTransform = animator.transform;
SpriteRenderer sprite = animator.GetComponent<SpriteRenderer>();
myWidth = sprite.bounds.extents.x;
myHeight = sprite.bounds.extents.y;
animator.SetBool("MovingRight", true);
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if(Vector3.Distance(myTransform.position, player.transform.position) < alertDistance)
{
animator.SetBool("Alerted", true);
}
Vector2 lineCastPosition = myTransform.position + myTransform.right * myWidth;
bool isOnGround = Physics2D.Linecast(lineCastPosition, lineCastPosition + Vector2.down, enemyMask);
Debug.DrawLine(lineCastPosition, lineCastPosition + Vector2.down);
Vector2 right = new Vector2(myTransform.right.x, myTransform.right.y);
bool isBlocked = Physics2D.Linecast(lineCastPosition, lineCastPosition + right * 0.1f, enemyMask);
Debug.DrawLine(lineCastPosition, lineCastPosition + right * 0.1f);
if(!isOnGround || isBlocked)
{
animator.SetBool("MovingRight", false);
}
else
{