Skip to content

Commit 5a404b2

Browse files
committed
Merge branch 'enemies' into main
2 parents 747b362 + 83ce765 commit 5a404b2

8 files changed

Lines changed: 256 additions & 8 deletions

File tree

Assets/Scenes/WebEasy.unity

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ GameObject:
423423
serializedVersion: 6
424424
m_Component:
425425
- component: {fileID: 741867331}
426+
- component: {fileID: 741867332}
427+
- component: {fileID: 741867333}
426428
m_Layer: 0
427-
m_Name: Waypoint5
429+
m_Name: CandyBowl
428430
m_TagString: Untagged
429431
m_Icon: {fileID: 0}
430432
m_NavMeshLayer: 0
@@ -444,6 +446,69 @@ Transform:
444446
m_Father: {fileID: 2052518869}
445447
m_RootOrder: 4
446448
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
449+
--- !u!212 &741867332
450+
SpriteRenderer:
451+
m_ObjectHideFlags: 0
452+
m_CorrespondingSourceObject: {fileID: 0}
453+
m_PrefabInstance: {fileID: 0}
454+
m_PrefabAsset: {fileID: 0}
455+
m_GameObject: {fileID: 741867330}
456+
m_Enabled: 1
457+
m_CastShadows: 0
458+
m_ReceiveShadows: 0
459+
m_DynamicOccludee: 1
460+
m_MotionVectors: 1
461+
m_LightProbeUsage: 1
462+
m_ReflectionProbeUsage: 1
463+
m_RayTracingMode: 0
464+
m_RayTraceProcedural: 0
465+
m_RenderingLayerMask: 1
466+
m_RendererPriority: 0
467+
m_Materials:
468+
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
469+
m_StaticBatchInfo:
470+
firstSubMesh: 0
471+
subMeshCount: 0
472+
m_StaticBatchRoot: {fileID: 0}
473+
m_ProbeAnchor: {fileID: 0}
474+
m_LightProbeVolumeOverride: {fileID: 0}
475+
m_ScaleInLightmap: 1
476+
m_ReceiveGI: 1
477+
m_PreserveUVs: 0
478+
m_IgnoreNormalsForChartDetection: 0
479+
m_ImportantGI: 0
480+
m_StitchLightmapSeams: 1
481+
m_SelectedEditorRenderState: 0
482+
m_MinimumChartSize: 4
483+
m_AutoUVMaxDistance: 0.5
484+
m_AutoUVMaxAngle: 89
485+
m_LightmapParameters: {fileID: 0}
486+
m_SortingLayerID: 0
487+
m_SortingLayer: 0
488+
m_SortingOrder: 0
489+
m_Sprite: {fileID: 21300000, guid: 137346d391986b341b05c87fe100d5f7, type: 3}
490+
m_Color: {r: 0.100427166, g: 0.8584906, b: 0.1641129, a: 1}
491+
m_FlipX: 0
492+
m_FlipY: 0
493+
m_DrawMode: 0
494+
m_Size: {x: 1, y: 1}
495+
m_AdaptiveModeThreshold: 0.5
496+
m_SpriteTileMode: 0
497+
m_WasSpriteAssigned: 1
498+
m_MaskInteraction: 0
499+
m_SpriteSortPoint: 0
500+
--- !u!114 &741867333
501+
MonoBehaviour:
502+
m_ObjectHideFlags: 0
503+
m_CorrespondingSourceObject: {fileID: 0}
504+
m_PrefabInstance: {fileID: 0}
505+
m_PrefabAsset: {fileID: 0}
506+
m_GameObject: {fileID: 741867330}
507+
m_Enabled: 1
508+
m_EditorHideFlags: 0
509+
m_Script: {fileID: 11500000, guid: 552313e2c7ef41343a82b2cf388fb60e, type: 3}
510+
m_Name:
511+
m_EditorClassIdentifier:
447512
--- !u!1 &783697816
448513
GameObject:
449514
m_ObjectHideFlags: 0
@@ -652,6 +717,7 @@ GameObject:
652717
m_Component:
653718
- component: {fileID: 1714582150}
654719
- component: {fileID: 1714582149}
720+
- component: {fileID: 1714582151}
655721
m_Layer: 0
656722
m_Name: Enemy
657723
m_TagString: Untagged
@@ -718,12 +784,26 @@ Transform:
718784
m_PrefabAsset: {fileID: 0}
719785
m_GameObject: {fileID: 1714582148}
720786
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
721-
m_LocalPosition: {x: -3.528144, y: -0.5923052, z: -13.6306505}
787+
m_LocalPosition: {x: -0.72, y: -1.31, z: -13.6306505}
722788
m_LocalScale: {x: 1, y: 1, z: 1}
723789
m_Children: []
724790
m_Father: {fileID: 0}
725791
m_RootOrder: 1
726792
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
793+
--- !u!114 &1714582151
794+
MonoBehaviour:
795+
m_ObjectHideFlags: 0
796+
m_CorrespondingSourceObject: {fileID: 0}
797+
m_PrefabInstance: {fileID: 0}
798+
m_PrefabAsset: {fileID: 0}
799+
m_GameObject: {fileID: 1714582148}
800+
m_Enabled: 1
801+
m_EditorHideFlags: 0
802+
m_Script: {fileID: 11500000, guid: 7977eea0e4da7dd4bb6dde066cb74d1d, type: 3}
803+
m_Name:
804+
m_EditorClassIdentifier:
805+
speed: 2
806+
health: 10
727807
--- !u!1 &1848384324
728808
GameObject:
729809
m_ObjectHideFlags: 0
@@ -2734,7 +2814,7 @@ GameObject:
27342814
- component: {fileID: 2052518870}
27352815
m_Layer: 0
27362816
m_Name: Path
2737-
m_TagString: Untagged
2817+
m_TagString: Path
27382818
m_Icon: {fileID: 0}
27392819
m_NavMeshLayer: 0
27402820
m_StaticEditorFlags: 0

Assets/Scripts/BowlController.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class BowlController : MonoBehaviour
6+
{
7+
GameObject carrier = null;
8+
// Start is called before the first frame update
9+
void Start()
10+
{
11+
12+
}
13+
14+
// Update is called once per frame
15+
void Update()
16+
{
17+
if (carrier != null) {
18+
transform.position = carrier.transform.position;
19+
}
20+
}
21+
22+
public bool Carry(GameObject newCarrier) {
23+
if (carrier != null) {
24+
return false;
25+
}
26+
else {
27+
carrier = newCarrier;
28+
return true;
29+
}
30+
}
31+
32+
public void Drop() {
33+
carrier = null;
34+
}
35+
}

Assets/Scripts/BowlController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/EnemyController.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class EnemyController : MonoBehaviour
6+
{
7+
public float speed = 1f;
8+
public int health = 10;
9+
bool carrying = false;
10+
Transform pathContainer;
11+
BowlController candyBowl;
12+
13+
// Start is called before the first frame update
14+
void Start()
15+
{
16+
// Create waypoint list from path object
17+
pathContainer = GameObject.FindGameObjectWithTag("Path").transform;
18+
Vector3[] waypoints = new Vector3[pathContainer.childCount];
19+
for (int i = 0; i < waypoints.Length; i++) {
20+
waypoints[i] = pathContainer.GetChild(i).position;
21+
}
22+
23+
// Get bowl object
24+
candyBowl = GameObject.FindGameObjectWithTag("Bowl").GetComponent<BowlController>();
25+
26+
// Start following the path
27+
StartCoroutine(FollowPath(waypoints));
28+
}
29+
30+
// Path following coroutine
31+
IEnumerator FollowPath(Vector3[] waypoints) {
32+
// Move to first waypoint and set up targets
33+
transform.position = waypoints[0];
34+
int targetWaypointIndex = 1;
35+
Vector3 targetWaypoint = waypoints[targetWaypointIndex];
36+
LookAt2D(targetWaypoint);
37+
int movementDirection = 1;
38+
39+
// Movement loop
40+
while (true) {
41+
// Move towards target waypoint
42+
transform.position = Vector3.MoveTowards(transform.position, targetWaypoint, speed * Time.deltaTime);
43+
44+
// Set new target once target is reached
45+
if (transform.position == targetWaypoint) {
46+
// Refresh waypoint list
47+
waypoints = new Vector3[pathContainer.childCount];
48+
for (int i = 0; i < waypoints.Length; i++) {
49+
waypoints[i] = pathContainer.GetChild(i).position;
50+
}
51+
if (targetWaypointIndex > waypoints.Length - 1) {
52+
targetWaypointIndex = waypoints.Length - 1;
53+
}
54+
55+
// Destroy if at the first waypoint
56+
if (targetWaypointIndex == 0) {
57+
Destroy(gameObject);
58+
}
59+
// Remove waypoint if carrying bowl
60+
if (carrying) {
61+
if (targetWaypointIndex != 0) {
62+
Destroy(pathContainer.GetChild(targetWaypointIndex).gameObject);
63+
}
64+
else {
65+
// Loose condition
66+
print("Game over, all your candy is belong to us.");
67+
candyBowl.Drop();
68+
// idk restart menu???
69+
}
70+
}
71+
// Final target logic
72+
if (targetWaypointIndex == waypoints.Length - 1) {
73+
// Turn around
74+
movementDirection = -1;
75+
76+
// Attempt to carry bowl
77+
carrying = candyBowl.Carry(gameObject);
78+
}
79+
80+
// Set next target
81+
targetWaypointIndex += movementDirection;
82+
targetWaypoint = waypoints[targetWaypointIndex];
83+
LookAt2D(targetWaypoint);
84+
}
85+
yield return null;
86+
}
87+
}
88+
89+
// 2D Lookat
90+
void LookAt2D(Vector3 targetPoint) {
91+
targetPoint.x -= transform.position.x;
92+
targetPoint.y -= transform.position.y;
93+
float angle = Mathf.Atan2(targetPoint.y, targetPoint.x) * Mathf.Rad2Deg;
94+
angle -= 90f;
95+
transform.rotation = Quaternion.Euler(0, 0, angle);
96+
}
97+
98+
// Update is called once per frame
99+
void Update()
100+
{
101+
}
102+
}

Assets/Scripts/EnemyController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Sprites/WhitePixel.png.meta

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ProjectSettings/PresetManager.asset

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44
PresetManager:
55
m_ObjectHideFlags: 0
66
serializedVersion: 2
7-
m_DefaultPresets: {}
7+
m_DefaultPresets:
8+
- first:
9+
m_NativeTypeID: 1210832254
10+
m_ManagedTypePPtr: {fileID: 0}
11+
m_ManagedTypeFallback:
12+
second:
13+
- m_Preset: {fileID: 0}
14+
m_Filter:
15+
m_Disabled: 0

ProjectSettings/TagManager.asset

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
--- !u!78 &1
44
TagManager:
55
serializedVersion: 2
6-
tags: []
6+
tags:
7+
- Path
78
layers:
89
- Default
910
- TransparentFX

0 commit comments

Comments
 (0)