2022-10-02 18:45:58 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class ThugModel
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
public string name;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
public Vector3 position;
|
|
|
|
|
|
|
|
public ThugModel(string _name, Vector3 _position)
|
|
|
|
{
|
|
|
|
name = _name;
|
|
|
|
position = _position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public class NPCManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
GameObject NPCCollection;
|
|
|
|
public List<ThugModel> thugs;
|
|
|
|
|
|
|
|
public ThugModel bossThug;
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
NPCCollection = GameObject.FindGameObjectWithTag("NPCCollection");
|
|
|
|
if (NPCCollection == null)
|
|
|
|
{
|
|
|
|
throw new Exception("Object not found");
|
|
|
|
}
|
2023-01-05 14:19:56 +01:00
|
|
|
if (GameObject.FindGameObjectWithTag("EnemyCollection").transform.Find(bossThug.name) == null)
|
|
|
|
{
|
|
|
|
Debug.Log("Build me :D");
|
|
|
|
CreateBossThug();
|
|
|
|
CreateThugs();
|
|
|
|
}
|
2022-10-02 18:45:58 +02:00
|
|
|
}
|
2023-01-05 14:19:56 +01:00
|
|
|
|
2022-10-02 18:45:58 +02:00
|
|
|
|
|
|
|
private void CreateThugs()
|
|
|
|
{
|
|
|
|
var model = Resources.Load("SampleScene/Enemies/Thug") as GameObject;
|
|
|
|
|
|
|
|
foreach (var thug in thugs)
|
|
|
|
{
|
|
|
|
var ThugClone = GameObject.Instantiate(model, thug.position, Quaternion.identity, NPCCollection.transform);
|
2022-12-21 23:32:51 +01:00
|
|
|
|
2022-10-02 18:45:58 +02:00
|
|
|
ThugClone.name = thug.name;
|
|
|
|
ThugClone.transform.SetParent(NPCCollection.transform);
|
2022-12-13 01:03:03 +01:00
|
|
|
|
|
|
|
//Debug.Log("Thug Name: " + ThugClone.name + " Positions: " + ThugClone.transform.position.x + " + " + ThugClone.transform.position.y + " + " + ThugClone.transform.position.z);
|
|
|
|
//Debug.Log("Thug Name: " + ThugClone.name + " Local Positions: " + ThugClone.transform.localPosition.x + " + " + ThugClone.transform.localPosition.y + " + " + ThugClone.transform.localPosition.z);
|
|
|
|
|
2023-01-04 21:23:02 +01:00
|
|
|
ThugClone.GetComponent<NPC>().Name = thug.name;
|
|
|
|
|
|
|
|
ThugClone.GetComponent<Enemy>().enemyName = thug.name; //delete and set in the controller todo?
|
|
|
|
ThugClone.GetComponent<Enemy>().MinionName = "Thug";
|
|
|
|
ThugClone.GetComponent<Enemy>().isKilled = PlayerPrefs.HasKey(thug.name + "-S") ? PlayerPrefs.GetInt(thug.name + "-S") : 0;
|
|
|
|
|
2022-10-02 18:45:58 +02:00
|
|
|
|
|
|
|
if (PlayerPrefs.HasKey(thug.name + "-S.health"))
|
|
|
|
{
|
2023-01-04 21:23:02 +01:00
|
|
|
ThugClone.GetComponent<Enemy>().health = PlayerPrefs.GetFloat(thug.name + "-S.health");
|
2022-10-02 18:45:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dont set up it manually, let allow logic in Following Enemy scriptmanage avaible itself
|
|
|
|
//ThugClone.SetActive(PlayerPrefs.HasKey(thug.name + "-S") ? !Convert.ToBoolean(PlayerPrefs.GetInt(thug.name + "-S")) : true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CreateBossThug()
|
|
|
|
{
|
2023-01-05 14:19:56 +01:00
|
|
|
Debug.Log("BOSS THUG IS CREATED!");
|
2022-10-02 18:45:58 +02:00
|
|
|
var modelBossThug = Resources.Load("SampleScene/Enemies/BossThug") as GameObject;
|
|
|
|
|
|
|
|
var BossThugClone = GameObject.Instantiate(modelBossThug, bossThug.position, Quaternion.identity, NPCCollection.transform);
|
|
|
|
|
|
|
|
BossThugClone.name = bossThug.name;
|
|
|
|
BossThugClone.transform.SetParent(NPCCollection.transform);
|
2023-01-04 21:23:02 +01:00
|
|
|
|
|
|
|
BossThugClone.GetComponent<NPC>().Name = bossThug.name;
|
|
|
|
|
2022-10-02 18:45:58 +02:00
|
|
|
BossThugClone.GetComponent<FollowingEnemy>().enemyName = bossThug.name; //delete and set in the controller todo?
|
2023-01-04 21:23:02 +01:00
|
|
|
BossThugClone.GetComponent<FollowingEnemy>().MinionName = "Thug";
|
|
|
|
|
2022-10-02 18:45:58 +02:00
|
|
|
BossThugClone.SetActive(PlayerPrefs.HasKey(bossThug.name + "-S") ? !Convert.ToBoolean(PlayerPrefs.GetInt(bossThug.name + "-S")) : true);
|
|
|
|
|
|
|
|
BossThugClone.GetComponent<FollowingEnemy>().isPanelEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|