Parallaxing, enemy
This commit is contained in:
parent
92f929fc2b
commit
338ab550f0
10 changed files with 380 additions and 4 deletions
|
@ -56,7 +56,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Assets\Scripts\CameraController.cs" />
|
<Compile Include="Assets\Scripts\CameraController.cs" />
|
||||||
|
<Compile Include="Assets\Scripts\EnemyController.cs" />
|
||||||
<Compile Include="Assets\Scripts\OwnCharacterController.cs" />
|
<Compile Include="Assets\Scripts\OwnCharacterController.cs" />
|
||||||
|
<Compile Include="Assets\Scripts\Parallaxing.cs" />
|
||||||
<Compile Include="Assets\Scripts\RocketScript.cs" />
|
<Compile Include="Assets\Scripts\RocketScript.cs" />
|
||||||
<Compile Include="Assets\Scripts\Tiling.cs" />
|
<Compile Include="Assets\Scripts\Tiling.cs" />
|
||||||
<Compile Include="Assets\Scripts\WeaponFireController.cs" />
|
<Compile Include="Assets\Scripts\WeaponFireController.cs" />
|
||||||
|
|
147
Assets/Prefabs/Enemy.prefab
Normal file
147
Assets/Prefabs/Enemy.prefab
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1 &7250562544566202694
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 7250562544566202698}
|
||||||
|
- component: {fileID: 7250562544566202699}
|
||||||
|
- component: {fileID: 7250562544566202696}
|
||||||
|
- component: {fileID: 7250562544566202697}
|
||||||
|
- component: {fileID: -1018939148389277147}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: Enemy
|
||||||
|
m_TagString: Enemy
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &7250562544566202698
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7250562544566202694}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: -0.31, y: 4.27, 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 &7250562544566202699
|
||||||
|
SpriteRenderer:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7250562544566202694}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_CastShadows: 0
|
||||||
|
m_ReceiveShadows: 0
|
||||||
|
m_DynamicOccludee: 1
|
||||||
|
m_MotionVectors: 1
|
||||||
|
m_LightProbeUsage: 1
|
||||||
|
m_ReflectionProbeUsage: 1
|
||||||
|
m_RayTracingMode: 0
|
||||||
|
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_ReceiveGI: 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: -13315653866412880, guid: 22df4be82d91637658b965dd24a4a591, type: 3}
|
||||||
|
m_Color: {r: 1, g: 1, b: 1, a: 1}
|
||||||
|
m_FlipX: 0
|
||||||
|
m_FlipY: 0
|
||||||
|
m_DrawMode: 0
|
||||||
|
m_Size: {x: 0.27, y: 0.5}
|
||||||
|
m_AdaptiveModeThreshold: 0.5
|
||||||
|
m_SpriteTileMode: 0
|
||||||
|
m_WasSpriteAssigned: 1
|
||||||
|
m_MaskInteraction: 0
|
||||||
|
m_SpriteSortPoint: 0
|
||||||
|
--- !u!50 &7250562544566202696
|
||||||
|
Rigidbody2D:
|
||||||
|
serializedVersion: 4
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7250562544566202694}
|
||||||
|
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: 0
|
||||||
|
m_Constraints: 4
|
||||||
|
--- !u!61 &7250562544566202697
|
||||||
|
BoxCollider2D:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7250562544566202694}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_Density: 1
|
||||||
|
m_Material: {fileID: 0}
|
||||||
|
m_IsTrigger: 0
|
||||||
|
m_UsedByEffector: 0
|
||||||
|
m_UsedByComposite: 0
|
||||||
|
m_Offset: {x: -0.046511114, y: 0}
|
||||||
|
m_SpriteTilingProperty:
|
||||||
|
border: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
pivot: {x: 0.5, y: 0.5}
|
||||||
|
oldSize: {x: 0.27, y: 0.5}
|
||||||
|
newSize: {x: 0.27, y: 0.5}
|
||||||
|
adaptiveTilingThreshold: 0.5
|
||||||
|
drawMode: 0
|
||||||
|
adaptiveTiling: 0
|
||||||
|
m_AutoTiling: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Size: {x: 0.17697775, y: 0.5}
|
||||||
|
m_EdgeRadius: 0
|
||||||
|
--- !u!114 &-1018939148389277147
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7250562544566202694}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: a86eb57291c5f566d8b1cb9f87a029d9, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
target: {fileID: 0}
|
||||||
|
speed: 1.1
|
7
Assets/Prefabs/Enemy.prefab.meta
Normal file
7
Assets/Prefabs/Enemy.prefab.meta
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ef6e23d6fe1e28e8c809679081854c6a
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -132,6 +132,7 @@ GameObject:
|
||||||
- component: {fileID: 996257476}
|
- component: {fileID: 996257476}
|
||||||
- component: {fileID: 996257475}
|
- component: {fileID: 996257475}
|
||||||
- component: {fileID: 996257477}
|
- component: {fileID: 996257477}
|
||||||
|
- component: {fileID: 996257478}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Underground
|
m_Name: Underground
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -219,6 +220,19 @@ MonoBehaviour:
|
||||||
hasARightBuddy: 0
|
hasARightBuddy: 0
|
||||||
hasALeftBuddy: 0
|
hasALeftBuddy: 0
|
||||||
reverseScale: 0
|
reverseScale: 0
|
||||||
|
--- !u!114 &996257478
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 996257474}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bd5c70ae65614c79a9c0670d4eb84eff, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
smoothing: 1
|
||||||
--- !u!1 &1043406433
|
--- !u!1 &1043406433
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -327,7 +341,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1351818047}
|
m_GameObject: {fileID: 1351818047}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -5.59, y: 2.59, z: -5.0090327}
|
m_LocalPosition: {x: -5.59, y: 2.59, z: -29.99}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
|
@ -359,6 +373,7 @@ GameObject:
|
||||||
- component: {fileID: 1372634518}
|
- component: {fileID: 1372634518}
|
||||||
- component: {fileID: 1372634517}
|
- component: {fileID: 1372634517}
|
||||||
- component: {fileID: 1372634519}
|
- component: {fileID: 1372634519}
|
||||||
|
- component: {fileID: 1372634520}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Hills
|
m_Name: Hills
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -424,7 +439,7 @@ Transform:
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1372634516}
|
m_GameObject: {fileID: 1372634516}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
m_LocalPosition: {x: -5, y: 1.49, z: 0}
|
m_LocalPosition: {x: -5, y: 1.49, z: 10}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
|
@ -446,6 +461,19 @@ MonoBehaviour:
|
||||||
hasARightBuddy: 0
|
hasARightBuddy: 0
|
||||||
hasALeftBuddy: 0
|
hasALeftBuddy: 0
|
||||||
reverseScale: 0
|
reverseScale: 0
|
||||||
|
--- !u!114 &1372634520
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1372634516}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bd5c70ae65614c79a9c0670d4eb84eff, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
smoothing: 1
|
||||||
--- !u!1 &1508769553
|
--- !u!1 &1508769553
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -458,6 +486,7 @@ GameObject:
|
||||||
- component: {fileID: 1508769554}
|
- component: {fileID: 1508769554}
|
||||||
- component: {fileID: 1508769556}
|
- component: {fileID: 1508769556}
|
||||||
- component: {fileID: 1508769557}
|
- component: {fileID: 1508769557}
|
||||||
|
- component: {fileID: 1508769558}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Ground
|
m_Name: Ground
|
||||||
m_TagString: Ground
|
m_TagString: Ground
|
||||||
|
@ -555,8 +584,8 @@ EdgeCollider2D:
|
||||||
- {x: 3.736737, y: 1.6933966}
|
- {x: 3.736737, y: 1.6933966}
|
||||||
- {x: 4.2887454, y: 1.7337929}
|
- {x: 4.2887454, y: 1.7337929}
|
||||||
- {x: 4.6893935, y: 1.8305986}
|
- {x: 4.6893935, y: 1.8305986}
|
||||||
- {x: 5.1891747, y: 1.9184827}
|
- {x: 5.097042, y: 1.9070681}
|
||||||
- {x: 5.214496, y: 1.9328326}
|
- {x: 5.120733, y: 1.9100034}
|
||||||
--- !u!114 &1508769557
|
--- !u!114 &1508769557
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -573,6 +602,19 @@ MonoBehaviour:
|
||||||
hasARightBuddy: 0
|
hasARightBuddy: 0
|
||||||
hasALeftBuddy: 0
|
hasALeftBuddy: 0
|
||||||
reverseScale: 0
|
reverseScale: 0
|
||||||
|
--- !u!114 &1508769558
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1508769553}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bd5c70ae65614c79a9c0670d4eb84eff, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
smoothing: 1
|
||||||
--- !u!1 &2053847420
|
--- !u!1 &2053847420
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -733,3 +775,82 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
prefab: {fileID: 5991448782009560204, guid: 7debf3c35b28387fdbec1c1c9942afae, type: 3}
|
prefab: {fileID: 5991448782009560204, guid: 7debf3c35b28387fdbec1c1c9942afae, type: 3}
|
||||||
firePoint: {fileID: 1043406434}
|
firePoint: {fileID: 1043406434}
|
||||||
|
--- !u!1001 &7250562544796225521
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: -1018939148389277147, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: target
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 2053847422}
|
||||||
|
- target: {fileID: -1018939148389277147, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: speed
|
||||||
|
value: 6
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202694, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: Enemy
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: -0.32
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: 2.49
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_RootOrder
|
||||||
|
value: 5
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7250562544566202698, guid: ef6e23d6fe1e28e8c809679081854c6a,
|
||||||
|
type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: ef6e23d6fe1e28e8c809679081854c6a, type: 3}
|
||||||
|
|
24
Assets/Scripts/EnemyController.cs
Normal file
24
Assets/Scripts/EnemyController.cs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class EnemyController : MonoBehaviour
|
||||||
|
{
|
||||||
|
public Transform target;
|
||||||
|
public float speed;
|
||||||
|
private Rigidbody2D _rb;
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
_rb = GetComponent<Rigidbody2D>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
var diff = target.position - transform.position;
|
||||||
|
diff.Normalize();
|
||||||
|
_rb.AddForce(diff * speed);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/EnemyController.cs.meta
Normal file
11
Assets/Scripts/EnemyController.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a86eb57291c5f566d8b1cb9f87a029d9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
51
Assets/Scripts/Parallaxing.cs
Normal file
51
Assets/Scripts/Parallaxing.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class Parallaxing : MonoBehaviour
|
||||||
|
{
|
||||||
|
private Transform _background;
|
||||||
|
private float _parallaxScale;
|
||||||
|
public float smoothing = 1f;
|
||||||
|
|
||||||
|
private Transform _cam; // reference to the main cameras transform
|
||||||
|
private Vector3 _previousCamPos; // the position of the camera in the previous frame
|
||||||
|
|
||||||
|
// Is called before Start(). Great for references.
|
||||||
|
void Awake () {
|
||||||
|
// set up the camera reference
|
||||||
|
_cam = Camera.main.transform;
|
||||||
|
_background = transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
// The previous frame had the current frame's camera position
|
||||||
|
_previousCamPos = _cam.position;
|
||||||
|
|
||||||
|
// asigning coresponding parallaxScale
|
||||||
|
_parallaxScale = _background.position.z * -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
// the parallax is the opposite of the camera movement because the previous frame multiplied by the scale
|
||||||
|
float parallax = (_previousCamPos.x - _cam.position.x) * _parallaxScale;
|
||||||
|
|
||||||
|
// set a target x position which is the current position plus the parallax
|
||||||
|
var position = _background.position;
|
||||||
|
float backgroundTargetPosX = position.x + parallax;
|
||||||
|
|
||||||
|
// create a target position which is the background's current position with it's target x position
|
||||||
|
Vector3 backgroundTargetPos = new Vector3(backgroundTargetPosX, position.y, position.z);
|
||||||
|
|
||||||
|
// fade between current position and the target position using lerp
|
||||||
|
position = Vector3.Lerp(position, backgroundTargetPos, smoothing * Time.deltaTime);
|
||||||
|
_background.position = position;
|
||||||
|
|
||||||
|
// set the previousCamPos to the camera's position at the end of the frame
|
||||||
|
_previousCamPos = _cam.position;
|
||||||
|
}
|
||||||
|
}
|
3
Assets/Scripts/Parallaxing.cs.meta
Normal file
3
Assets/Scripts/Parallaxing.cs.meta
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bd5c70ae65614c79a9c0670d4eb84eff
|
||||||
|
timeCreated: 1604695093
|
|
@ -33,4 +33,13 @@ public class RocketScript : MonoBehaviour
|
||||||
|
|
||||||
_rb.AddForce(new Vector2(_goingRight ? 10 : -10, 0));
|
_rb.AddForce(new Vector2(_goingRight ? 10 : -10, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnCollisionEnter2D(Collision2D other)
|
||||||
|
{
|
||||||
|
if (!other.gameObject.CompareTag("Enemy"))
|
||||||
|
return;
|
||||||
|
gameObject.SetActive(false);
|
||||||
|
_rb.velocity = Vector2.zero;
|
||||||
|
Destroy(other.gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ TagManager:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
tags:
|
tags:
|
||||||
- Ground
|
- Ground
|
||||||
|
- Enemy
|
||||||
layers:
|
layers:
|
||||||
- Default
|
- Default
|
||||||
- TransparentFX
|
- TransparentFX
|
||||||
|
|
Loading…
Reference in a new issue