From 1d13cb09df78a1e89cbde7144ea9bb7cb1e27102 Mon Sep 17 00:00:00 2001 From: dart Date: Sat, 2 Apr 2022 20:42:29 +0300 Subject: [PATCH] create mob attack --- .gitignore | 1 + ldjam50/Assets/Prefabs/character.prefab | 2 +- ldjam50/Assets/Prefabs/mob.prefab | 6 +++- ldjam50/Assets/Scripts/Character.cs | 5 +++ ldjam50/Assets/Scripts/Mob.cs | 42 +++++++++++++++++++++- ldjam50/Assets/Scripts/OverMind.cs | 46 ++++++++++++++++++++++++ ldjam50/Assets/Scripts/OverMind.cs.meta | 11 ++++++ ldjam50/ProjectSettings/TagManager.asset | 3 +- 8 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 ldjam50/Assets/Scripts/OverMind.cs create mode 100644 ldjam50/Assets/Scripts/OverMind.cs.meta diff --git a/.gitignore b/.gitignore index ededc67..8b26de5 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,4 @@ Temp obj Logs /.gitignore~ +/ldjam50/Logs/ApiUpdaterCheck.txt diff --git a/ldjam50/Assets/Prefabs/character.prefab b/ldjam50/Assets/Prefabs/character.prefab index e828595..f75c964 100644 --- a/ldjam50/Assets/Prefabs/character.prefab +++ b/ldjam50/Assets/Prefabs/character.prefab @@ -125,7 +125,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: -0.020021677, y: 0.0039904118} diff --git a/ldjam50/Assets/Prefabs/mob.prefab b/ldjam50/Assets/Prefabs/mob.prefab index b786583..602a019 100644 --- a/ldjam50/Assets/Prefabs/mob.prefab +++ b/ldjam50/Assets/Prefabs/mob.prefab @@ -43,7 +43,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: -0.0049001575, y: -0.026252389} @@ -71,6 +71,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7dc89d6f20b8bd496a76c3dad9b1b832, type: 3} m_Name: m_EditorClassIdentifier: + characterObject: {fileID: 0} + moveSpeed: 0 + minDist: 0 + maxDist: 0 --- !u!1 &6540482753690656168 GameObject: m_ObjectHideFlags: 0 diff --git a/ldjam50/Assets/Scripts/Character.cs b/ldjam50/Assets/Scripts/Character.cs index 61fa575..2a9af91 100644 --- a/ldjam50/Assets/Scripts/Character.cs +++ b/ldjam50/Assets/Scripts/Character.cs @@ -47,4 +47,9 @@ public StatReturn GetStats() }; return stats; } + + public void ApplyDamage(float newDamage) + { + damage += newDamage; + } } diff --git a/ldjam50/Assets/Scripts/Mob.cs b/ldjam50/Assets/Scripts/Mob.cs index 9554057..2c059ac 100644 --- a/ldjam50/Assets/Scripts/Mob.cs +++ b/ldjam50/Assets/Scripts/Mob.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -27,7 +28,34 @@ void Update() { //transform.position += transform.forward * moveSpeed * Time.deltaTime; - transform.position += (characterObject.transform.position-transform.position) * moveSpeed * Time.deltaTime; + + var rawCharacterVector = characterObject.transform.position - transform.position; + + var characterVector = new Vector3( + Mathf.Clamp(rawCharacterVector.x, -moveSpeed, moveSpeed), + Mathf.Clamp(rawCharacterVector.y, -moveSpeed, moveSpeed), + 0); + if (characterVector.x < 1f && characterVector.x > 0) + { + characterVector.x = 1f; + } + + if (characterVector.y < 1f && characterVector.y > 0) + { + characterVector.y = 1f; + } + + if (characterVector.x > 1f && characterVector.x < 0) + { + characterVector.x = 1f; + } + + if (characterVector.y > -1f && characterVector.y < 0) + { + characterVector.y = 1f; + } + //print(characterVector); + transform.position += (characterObject.transform.position-transform.position) * (moveSpeed * Time.deltaTime); @@ -38,4 +66,16 @@ void Update() } } } + + private void OnTriggerEnter2D(Collider2D col) + { + print("Detect"); + gameObject.SetActive(false); + } + + public void SetupMob(OverMind.MobParameters mobParameters) + { + characterObject = mobParameters.Character; + moveSpeed = mobParameters.MoveSpeed; + } } diff --git a/ldjam50/Assets/Scripts/OverMind.cs b/ldjam50/Assets/Scripts/OverMind.cs new file mode 100644 index 0000000..9d021d6 --- /dev/null +++ b/ldjam50/Assets/Scripts/OverMind.cs @@ -0,0 +1,46 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class OverMind : MonoBehaviour +{ + [SerializeField] private GameObject mob; + [SerializeField] private GameObject megaMob; + [SerializeField] private int pullSize; + + [SerializeField] private GameObject characterObject; + [SerializeField] private float mobMoveSpeed; + + private List _pullEnemies; + + public struct MobParameters + { + public float MoveSpeed; + public GameObject Character; + } + + void Start() + { + PreHeaterSpawn(); + } + + private void PreHeaterSpawn() + { + for (var i = 0; i < pullSize; i++) + { + var newMob = Instantiate(mob,transform); + + var newMobParameters = new MobParameters + { + MoveSpeed = mobMoveSpeed, + Character = characterObject + }; + + newMob.GetComponent().SetupMob(newMobParameters); + } + } + // Update is called once per frame + void Update() + { + } +} diff --git a/ldjam50/Assets/Scripts/OverMind.cs.meta b/ldjam50/Assets/Scripts/OverMind.cs.meta new file mode 100644 index 0000000..ca42074 --- /dev/null +++ b/ldjam50/Assets/Scripts/OverMind.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a35c03cf584d904acac0d316af6a31fb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ldjam50/ProjectSettings/TagManager.asset b/ldjam50/ProjectSettings/TagManager.asset index 1c92a78..b99ab8d 100644 --- a/ldjam50/ProjectSettings/TagManager.asset +++ b/ldjam50/ProjectSettings/TagManager.asset @@ -3,7 +3,8 @@ --- !u!78 &1 TagManager: serializedVersion: 2 - tags: [] + tags: + - Character layers: - Default - TransparentFX