Add pathing for enemies

This commit is contained in:
Isaac Shoebottom 2023-02-16 19:07:21 -04:00
parent 3ceb5634df
commit 2dad7631dd
18 changed files with 673 additions and 424 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -12,6 +12,7 @@ GameObject:
- component: {fileID: 2981135554967256007}
- component: {fileID: 1540579659150390887}
- component: {fileID: 7146678828090736945}
- component: {fileID: 2294062540900002317}
m_Layer: 0
m_Name: Generation
m_TagString: Untagged
@ -98,7 +99,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6d151e6102b72db4590ce83309573f1c, type: 3}
m_Name:
m_EditorClassIdentifier:
PathGameObject: {fileID: 0}
--- !u!50 &7146678828090736945
Rigidbody2D:
serializedVersion: 4
@ -107,7 +107,7 @@ Rigidbody2D:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1458536803320539101}
m_BodyType: 0
m_BodyType: 1
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
@ -117,6 +117,32 @@ Rigidbody2D:
m_GravityScale: 0
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_SleepingMode: 0
m_CollisionDetection: 0
m_Constraints: 0
--- !u!61 &2294062540900002317
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1458536803320539101}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
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

View File

@ -10,7 +10,9 @@ GameObject:
m_Component:
- component: {fileID: 328858392699145925}
- component: {fileID: 4841795318599809648}
- component: {fileID: 2671460795696364852}
- component: {fileID: 8192986790885562340}
- component: {fileID: -834716027335084487}
- component: {fileID: 8406881250321231346}
m_Layer: 0
m_Name: PathNode
m_TagString: Untagged
@ -27,7 +29,7 @@ Transform:
m_GameObject: {fileID: 2624247600710686983}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.7311517, y: 0.074633844, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 0.1, y: 0.1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
@ -75,7 +77,7 @@ SpriteRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 7482667652216324306, guid: 311925a002f4447b3a28927169b83ea6, type: 3}
m_Color: {r: 0, g: 0, b: 0, a: 0}
m_Color: {r: 1, g: 0, b: 0, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
@ -85,16 +87,62 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!65 &2671460795696364852
BoxCollider:
--- !u!50 &8192986790885562340
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2624247600710686983}
m_BodyType: 2
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: 0
--- !u!61 &-834716027335084487
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2624247600710686983}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_Enabled: 1
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, z: 0.2}
m_Center: {x: 0, y: 0, z: 0}
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!114 &8406881250321231346
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2624247600710686983}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2346c6ef8f7f55541b5f27987d960a46, type: 3}
m_Name:
m_EditorClassIdentifier:

View File

@ -123,6 +123,130 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1001 &287684445
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_RootOrder
value: 8
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.x
value: 11.76163
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.y
value: 2.9282274
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_Name
value: Waypoint 3
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
--- !u!1 &287684446 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
m_PrefabInstance: {fileID: 287684445}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &367263645
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.x
value: -8.71
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.y
value: 3.33
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_Name
value: Waypoint 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
--- !u!1 &367263646 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
m_PrefabInstance: {fileID: 367263645}
m_PrefabAsset: {fileID: 0}
--- !u!1 &449794919
GameObject:
m_ObjectHideFlags: 0
@ -181,12 +305,12 @@ SpriteRenderer:
m_SortingLayerID: -22961053
m_SortingLayer: -1
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: a92d11379a5e674489668c40439d778d, type: 3}
m_Sprite: {fileID: 5854342148761561055, guid: 8cdb315d4968ef847a63e52bd8847e5b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 2
m_Size: {x: 27.3, y: 14.3}
m_Size: {x: 22, y: 10.7}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
@ -200,12 +324,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 449794919}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.29, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &519420028
GameObject:
@ -446,7 +570,7 @@ GameObject:
- component: {fileID: 1014711458}
- component: {fileID: 1014711459}
m_Layer: 0
m_Name: Controller
m_Name: LevelController
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -460,12 +584,12 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1014711457}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 7.6740193, y: 7.8, z: -10.011237}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1014711459
MonoBehaviour:
@ -476,56 +600,15 @@ MonoBehaviour:
m_GameObject: {fileID: 1014711457}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 709edaf88476e014f9de790745097efd, type: 3}
m_Script: {fileID: 11500000, guid: 29744b92ef0fa824ba2c2dfaecd784ed, type: 3}
m_Name:
m_EditorClassIdentifier:
artist: {fileID: 2276488776047960095, guid: e7ecd0892a155ad40b2253fe45b2f43a, type: 3}
--- !u!1 &1292283376
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1292283378}
- component: {fileID: 1292283377}
m_Layer: 0
m_Name: Path
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1292283377
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292283376}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 62f8cdc29b6f43e4998a2750b3b9a023, type: 3}
m_Name:
m_EditorClassIdentifier:
waypointPrefab: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
enemyPrefab: {fileID: 1458536803320539101, guid: f1eab3cea41682c4ba2ff7c2b218fc0b, type: 3}
--- !u!4 &1292283378
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1292283376}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -10.78, y: 8.21, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
enemy: {fileID: 1458536803320539101, guid: f1eab3cea41682c4ba2ff7c2b218fc0b, type: 3}
waypoints:
- {fileID: 1556613419}
- {fileID: 367263646}
- {fileID: 287684446}
--- !u!1 &1321858736
GameObject:
m_ObjectHideFlags: 0
@ -619,13 +702,75 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1001 &1556613418
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_RootOrder
value: 6
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.x
value: -8.61
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.y
value: -6.2
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalPosition.z
value: -0.0487628
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 328858392699145925, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
propertyPath: m_Name
value: Waypoint 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
--- !u!1 &1556613419 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2624247600710686983, guid: fad75b8b6a5d5a6468eef0f0782ea835, type: 3}
m_PrefabInstance: {fileID: 1556613418}
m_PrefabAsset: {fileID: 0}
--- !u!1 &1644448702
GameObject:
m_ObjectHideFlags: 0
@ -691,5 +836,5 @@ Transform:
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@ -1,17 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class ArtistController : MonoBehaviour {
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
}

View File

@ -1,21 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameController : MonoBehaviour
{
public GameObject artist;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0)) {
Instantiate(artist, Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward, Quaternion.identity);
}
}
}

View File

@ -4,44 +4,37 @@ using System.Collections.Generic;
using UnityEngine;
public class GenerationController : MonoBehaviour {
internal GameObject[] waypoints;
private int waypointIndex = 1;
private Rigidbody2D rb;
public GameObject PathGameObject;
private Rigidbody2D rb;
// Start is called before the first frame update
private void Start() {
rb = GetComponent<Rigidbody2D>();
}
int pathIndex = 0;
// Update is called once per frame
void Update() { }
bool moving = false;
private void FixedUpdate() {
if (waypointIndex < waypoints.Length) {
var target = waypoints[waypointIndex].transform.position;
var direction = target - transform.position;
var f = transform.position + direction.normalized * 0.1f;
rb.MovePosition(f);
} else if (waypointIndex >= waypoints.Length) {
Destroy(gameObject);
}
}
private GameObject pathPointer;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
PathGameObject = GameObject.Find("Path");
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate() {
pathPointer = PathGameObject.GetComponent<PathingController>().waypointList[pathIndex] as GameObject;
if (!moving) {
Vector2 force = new Vector2(pathPointer.transform.position.x, pathPointer.transform.position.y);
rb.AddForce(force);
moving = true;
}
}
private void OnTriggerEnter2D(Collider2D col) {
if (col.gameObject == pathPointer) {
moving = false;
pathIndex++;
}
}
}
private void OnTriggerEnter2D(Collider2D col) {
if (col.gameObject == waypoints[waypointIndex]) {
waypointIndex++;
}
}
public void setWaypoints(GameObject[] waypointsIn) {
waypoints = waypointsIn;
}
}

View File

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class LevelController : MonoBehaviour {
public GameObject artist;
public GameObject enemy;
public GameObject[] waypoints;
private Queue<GameObject> enemies = new();
// Start is called before the first frame update
void Start() {
spawnEnemy(enemy, waypoints[0].transform.position);
}
// Update is called once per frame
void Update() {
if (Input.GetMouseButtonDown(0)) {
Instantiate(artist, Camera.main.ScreenToWorldPoint(Input.mousePosition) + Vector3.forward, Quaternion.identity);
}
}
private void spawnEnemy(GameObject enemyIn, Vector3 position) {
var e = Instantiate(enemyIn, position, Quaternion.identity);
var ec = e.GetComponent<GenerationController>();
ec.setWaypoints(waypoints);
enemies.Enqueue(e);
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 709edaf88476e014f9de790745097efd
guid: 29744b92ef0fa824ba2c2dfaecd784ed
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -1,44 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PathingController : MonoBehaviour {
public GameObject waypointPrefab;
public ArrayList waypointList = new ArrayList();
public GameObject enemyPrefab;
private ArrayList enemyList = new ArrayList();
int counter = 0;
// Start is called before the first frame update
void Start()
{
waypointList.Add(Instantiate(waypointPrefab, new Vector3(0, 0, 0), Quaternion.identity));
waypointList.Add(Instantiate(waypointPrefab, new Vector3(0, 5, 0), Quaternion.identity));
waypointList.Add(Instantiate(waypointPrefab, new Vector3(5, 5, 0), Quaternion.identity));
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate() {
if (counter == 0) {
enemyList.Add(Instantiate(enemyPrefab));
counter++;
}
else if (counter >= 50) {
counter = 0;
}
else {
counter++;
}
}
}

View File

@ -0,0 +1,8 @@
using UnityEngine;
public class WaypointController : MonoBehaviour {
private void Start() {
var transparent = new Color(1, 1, 1, 0);
GetComponent<SpriteRenderer>().color = transparent;
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 62f8cdc29b6f43e4998a2750b3b9a023
guid: 2346c6ef8f7f55541b5f27987d960a46
MonoImporter:
externalObjects: {}
serializedVersion: 2

Binary file not shown.

Before

Width:  |  Height:  |  Size: 356 B

View File

@ -1,134 +0,0 @@
fileFormatVersion: 2
guid: a92d11379a5e674489668c40439d778d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 0
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: WebGL
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,268 @@
fileFormatVersion: 2
guid: 8cdb315d4968ef847a63e52bd8847e5b
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: b2a9591990af98743ba3ff7cf1000886, type: 3}
textureImporterSettings:
alphaSource: 1
mipMapMode: 0
enableMipMap: 1
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
convertToNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 1
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
nPOTScale: 1
sRGBTexture: 1
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 0
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 0
flipbookColumns: 0
ignorePngGamma: 0
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
normalMap: 0
textureFormat: 0
maxTextureSize: 0
lightmap: 0
compressionQuality: 0
linearTexture: 0
grayScaleToAlpha: 0
rGBM: 0
cubemapConvolutionSteps: 0
cubemapConvolutionExponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
spriteImportData:
- name: MapBackground_1
originalName:
pivot: {x: 0.5, y: 0.5}
alignment: 0
border: {x: 0, y: 0, z: 0, w: 0}
rect:
serializedVersion: 2
x: 0
y: 0
width: 160
height: 90
spriteID: 7727cc21aa9fdbf49bee04c1ec06fe04
spriteBone: []
spriteOutline: []
vertices: []
spritePhysicsOutline: []
indices:
edges: []
tessellationDetail: 0
parentGroupIndex: -1
uvTransform: {x: 0, y: 0}
mosaicSpriteImportData: []
rigSpriteImportData:
- name: Layer 3
originalName:
pivot: {x: 0.5, y: 0.5}
alignment: 0
border: {x: 0, y: 0, z: 0, w: 0}
rect:
serializedVersion: 2
x: 4
y: 102
width: 160
height: 7
spriteID: a721b87cf029a4d438e02f9c39baaffa
spriteBone: []
spriteOutline: []
vertices: []
spritePhysicsOutline: []
indices:
edges: []
tessellationDetail: 0
parentGroupIndex: -1
uvTransform: {x: 4, y: 102}
- name: Layer 2
originalName:
pivot: {x: 0.5, y: 0.5}
alignment: 0
border: {x: 0, y: 0, z: 0, w: 0}
rect:
serializedVersion: 2
x: 172
y: 4
width: 10
height: 90
spriteID: d0b7aac24a8b46b4da3fe9da8fd435d9
spriteBone: []
spriteOutline: []
vertices: []
spritePhysicsOutline: []
indices:
edges: []
tessellationDetail: 0
parentGroupIndex: -1
uvTransform: {x: 22, y: 4}
- name: Layer 1
originalName:
pivot: {x: 0.5, y: 0.5}
alignment: 0
border: {x: 0, y: 0, z: 0, w: 0}
rect:
serializedVersion: 2
x: 4
y: 4
width: 160
height: 90
spriteID: 9447771bb342d324194f7575c963a72e
spriteBone: []
spriteOutline: []
vertices: []
spritePhysicsOutline: []
indices:
edges: []
tessellationDetail: 0
parentGroupIndex: -1
uvTransform: {x: 4, y: 4}
characterData:
bones: []
parts: []
dimension: {x: 0, y: 0}
characterGroups: []
boneReadOnly: 0
sharedRigSpriteImportData: []
sharedRigCharacterData:
bones: []
parts: []
dimension: {x: 0, y: 0}
characterGroups: []
boneReadOnly: 0
platformSettings:
- name: DefaultTexturePlatform
overridden: 0
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
forceMaximumCompressionQuality_BC6H_BC7: 0
crunchedCompression: 0
allowsAlphaSplitting: 0
androidETC2FallbackOverride: 0
- name: Standalone
overridden: 0
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
forceMaximumCompressionQuality_BC6H_BC7: 0
crunchedCompression: 0
allowsAlphaSplitting: 0
androidETC2FallbackOverride: 0
- name: Server
overridden: 0
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
forceMaximumCompressionQuality_BC6H_BC7: 0
crunchedCompression: 0
allowsAlphaSplitting: 0
androidETC2FallbackOverride: 0
- name: WebGL
overridden: 0
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
forceMaximumCompressionQuality_BC6H_BC7: 0
crunchedCompression: 0
allowsAlphaSplitting: 0
androidETC2FallbackOverride: 0
mosaicLayers: 1
characterMode: 1
documentPivot: {x: 0, y: 0}
documentAlignment: 7
importHiddenLayers: 0
layerMappingOption: 2
generatePhysicsShape: 0
paperDollMode: 0
keepDupilcateSpriteName: 1
skeletonAssetReferenceID:
spriteCategoryList:
categories: []
spritePackingTag:
resliceFromLayer: 0
mosaicPSDLayers: []
rigPSDLayers:
- name: Layer 3
spriteName: Layer 3
isGroup: 0
parentIndex: -1
spriteID: a721b87cf029a4d438e02f9c39baaffa
layerID: 4
mosaicPosition: {x: 4, y: 102}
flatten: 0
isImported: 1
isVisible: 1
- name: Layer 2
spriteName: Layer 2
isGroup: 0
parentIndex: -1
spriteID: d0b7aac24a8b46b4da3fe9da8fd435d9
layerID: 3
mosaicPosition: {x: 172, y: 4}
flatten: 0
isImported: 1
isVisible: 1
- name: Layer 1
spriteName: Layer 1
isGroup: 0
parentIndex: -1
spriteID: 9447771bb342d324194f7575c963a72e
layerID: 2
mosaicPosition: {x: 4, y: 4}
flatten: 0
isImported: 1
isVisible: 1
sharedRigPSDLayers: []
pSDLayerImportSetting: []
generateGOHierarchy: 0
textureAssetName:
prefabAssetName:
spriteLibAssetName:
skeletonAssetName:
secondarySpriteTextures: []

View File

@ -1,98 +0,0 @@
fileFormatVersion: 2
guid: e9c801220f35c7344bedeb9c40d10eb1
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

39
Steps.md Normal file
View File

@ -0,0 +1,39 @@
Tower Defense Game
Different Scenes for different levels, so, need:
1. A way to create towers independent of scene
2. A way to spawn enemies independent of scene
3. Waypoints should be static on a level, but can be moved around freely.
4. Way for objects to target first, closest, last, (strongest?)
5. Way for projectiles/attacks to affect enemies
6. Way to upgrade towers.
Implementation details:
1. A prefab for each tower. When clicking empty ground [check if no tower tagged type tower is below mouse pointer](https://gamedev.stackexchange.com/questions/121994/how-to-get-which-gameobject-the-mouse-is-over-in-unity) and if none found, create radial menu around cursor. Clicking away from any buttons closes the menu. When clicking a button to select a tower it will be placed at the original click point.
2. Prefab for each enemy. A level controller will need to spawn in enemies (Initialize them) and then find a way to pass in the array of waypoints. The level controller will have a public array of stored waypoints so it can pass in that object to each enemy. Once the waypoint number == array length then decrease lives/whatever, then destroy self
3. Prefab for waypoints. Potentially find a way to put them in empty game object and use the array of children at game startup.
4. Every interval of the tower, the tower will ray-cast in a radius around it, (or maybe use a shell cast (check in an expanding radius around the tower (or both))) and keep track of the first object in the enemy array, that is within the radius (compare distance between tower and enemy vs radius), and if closest, just use the smallest number in radius, last is the inverse of first. The array of enemies will have to be passed into each tower when it is spawned (if arrays are actually passed by reference in unity). Based on the initial distance between the tower and the enemy, estimate the amount of time it would take to throw a projectile/attack. Then predict where the enemy will be in that time. This process can be repeated for further accuracy (make it a function?)
5. A prefab for each projectile would be needed. You would need to pass in the angle, position when initiated, but also it's lifetime if it has one, or any additional information in a separate function. They should be deleted when they leave the viewport. Each should have a way to move itself in a script attached to it.
6. A radial menu like the buy menu should open up around the tower, allowing you to upgrade specific things about the tower based on it's type. The radial menu could have an outer rim which indicated how many upgrades it has based on a dashed line on the outer rim.
Aesthetic decisions:
The entrance should probably have a machine that spits out the enemies (undecided what they will look like, potentially extra fingers or other hallmarks of ai art, or could look like glitches like missingno or like a jumble of pixels). The towers should be things like Artist (the basic tower). It can be upgraded from pencils, to paint brushes which have a splash radius on hit, to a paint roller which penetrates multiple enemies and has weaker splash radius. Another tower might be a painter, which starts by throwing three drops of paint, and then upgrades to a big projectile with an AOE attack on the ground, and then throwing multiple of them. Come up with other spins on artist based attacks (pixel artist, digital artist). Losing lives could have an impact on the background, making it look more glitchy
Story (brief):
It is 2022 and the emergence of AI art is threatening digital art spaces. Artists band together to attack the AI in an all out brawl. Protect the integrity of art by stopping them before they get too far.
Potentially helpful links:
https://gamedevbeginner.com/how-to-get-a-variable-from-another-script-in-unity-the-right-way/
https://www.youtube.com/watch?v=2pCkInvkwZ0
https://forum.unity.com/threads/c-global-variables-available-to-all-scenes.544901/
https://stackoverflow.com/questions/68189868/how-can-i-make-a-variable-that-i-can-access-in-any-unity-scene-unity
https://learn.unity.com/tutorial/waypoints#