|
|
@@ -0,0 +1,92 @@
|
|
|
+using Sirenix.OdinInspector;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+public class DragonController : MonoBehaviour
|
|
|
+{
|
|
|
+ [LabelText("¼ä¸ô")] public float distance;
|
|
|
+ public int baseSortingOrder;
|
|
|
+ public int num;
|
|
|
+ public int damage;
|
|
|
+ public int demonicId;
|
|
|
+ public PlayerController player;
|
|
|
+ public List<Demonic> demonics;
|
|
|
+ public List<Vector3> targetPoss;
|
|
|
+ public Vector3 playerOffset;
|
|
|
+ public float lerpValue;
|
|
|
+
|
|
|
+ public void Update()
|
|
|
+ {
|
|
|
+ Vector3 pos = player.transform.position + playerOffset;
|
|
|
+ if(Vector3.Distance(pos, targetPoss[0]) >= distance)
|
|
|
+ {
|
|
|
+ targetPoss[0] = pos;
|
|
|
+ }
|
|
|
+ for(int i = 0; i < demonics.Count; i++)
|
|
|
+ {
|
|
|
+ Demonic demonic = demonics[i];
|
|
|
+ Vector3 demonicPos = demonic.transform.position;
|
|
|
+ if(Vector3.Distance(targetPoss[i],demonicPos) >= distance)
|
|
|
+ {
|
|
|
+ targetPoss[i + 1] = demonicPos;
|
|
|
+ }
|
|
|
+ demonic.transform.position = Vector3.Lerp(demonicPos, targetPoss[i], lerpValue * Time.deltaTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void Init()
|
|
|
+ {
|
|
|
+ Vector3 offset = Vector3.zero;
|
|
|
+ demonics = new List<Demonic>();
|
|
|
+ targetPoss = new List<Vector3>();
|
|
|
+ targetPoss.Add(player.transform.position + playerOffset);
|
|
|
+ for(int i = 0; i < num; i++)
|
|
|
+ {
|
|
|
+ Demonic demonic = CreateDemonic();
|
|
|
+ if(player.bodyTrans.localScale.x > 0)
|
|
|
+ {
|
|
|
+ offset = new Vector3(distance * (i + 1), 0, 0);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ offset = new Vector3(-distance * (i + 1), 0, 0);
|
|
|
+ }
|
|
|
+ demonic.transform.position += offset;
|
|
|
+ int order = baseSortingOrder + i;
|
|
|
+ demonic.SetSortingOrder(order);
|
|
|
+ demonics.Add(demonic);
|
|
|
+ targetPoss.Add(demonic.transform.position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Demonic CreateDemonic()
|
|
|
+ {
|
|
|
+ GameObject demonicPrefabs = player.demonicPrefabs[demonicId];
|
|
|
+ GameObject demonicObj = PoolManager.Instantiate(demonicPrefabs);
|
|
|
+ Demonic demonic = demonicObj.GetComponent<Demonic>();
|
|
|
+ float dir = player.bodyTrans.localScale.x;
|
|
|
+ demonic.ignoresOnState = true;
|
|
|
+ demonic.dragonTrigger.haveCollisionDamage = true;
|
|
|
+ demonic.beHitTrigger.gameObject.SetActive(false);
|
|
|
+ demonic.beSearchTrigger.gameObject.SetActive(false);
|
|
|
+ Vector3 offset = player.demonicSummonPos[demonicId];
|
|
|
+ if (dir > 0)
|
|
|
+ {
|
|
|
+ if (demonic.bodyTrans.localScale.x < 0)
|
|
|
+ {
|
|
|
+ demonic.Turn();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (demonic.bodyTrans.localScale.x > 0)
|
|
|
+ {
|
|
|
+ demonic.Turn();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ playerOffset = new Vector3(dir > 0 ? offset.x : -offset.x, offset.y, offset.z);
|
|
|
+ demonicObj.transform.position = player.transform.position + playerOffset;
|
|
|
+ demonic.Init();
|
|
|
+ return demonic;
|
|
|
+ }
|
|
|
+}
|