PJ/Assets/scripts/BossLogic.cs

247 lines
9.3 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Mathematics;
using System.Linq;
public class BossLogic : MonoBehaviour
{
public List<GameObject> Crystals;
public GameObject Liner;
public int[] Atacks;
public GameObject[] Rays;
public GameObject[] Attacks;
public float AtackSpeed;
public int orbitSpeed;
List<GameObject> Rayss;
[SerializeField]int St;
int[] stady1 = {0,1,2,3,4};
public int stady;
float AS;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
InvokeRepeating("Atacking", AS, AtackSpeed);
}
// Update is called once per frame
void FixedUpdate()
{ if(GameObject.Find("player")!=null){
for(int i =1; i<Crystals.Count(); i++)
{
if(Crystals[i]!=null){
Crystals[i].transform.RotateAround(Crystals[0].transform.position, Vector3.forward, orbitSpeed * Time.deltaTime);
Crystals[i].transform.Rotate(Vector3.forward, orbitSpeed * -Time.deltaTime);
}}
if(stady == 0){
for(int i = 0; i<stady1.Count(); i++)
{ if(Crystals[stady1[i]].GetComponent<EnityControl>().Lives < 10){
Crystals[stady1[i]].GetComponent<EnityControl>().Lives = 10;
CreateLineT(Crystals[0].transform.position, new Color(0,1,0), 0);}
}
if(stady == 1 && Crystals[0].GetComponent<EnityControl>().Lives < 10){for(int i =1; i<Crystals.Count(); i++){if(Crystals[i]!=null){CreateLineT(Crystals[i].transform.position, new Color(0,1,0), 0);}}
}
}}
}
public void Atacking()
{ if(GameObject.Find("player")!=null){
int ind;
int i = Crystals.Count(s => s == null );
switch(i)
{
case <3:
ind = UnityEngine.Random.Range(4,6);
att(ind);
stady = 0;
AS = 2;
break;
case <5:
ind = UnityEngine.Random.Range(4,7);
stady = 1;
att(ind);
break;
case <8:
ind = UnityEngine.Random.Range(0,8);
att(ind);
stady = 1;
AS = 1;
break;
case 8:
ind = 2;
AS = 0.5f;
att(ind);
stady =2;
break;
}
}
}
void att(int inda)
{
switch(inda)//1204
{
case 0:
AtackingSet(0);
CreateLineT(Crystals[1].transform.position, new Color(1,0,0),0);
break;
case 1:
AtackingSet(1);
CreateLineT(Crystals[2].transform.position, new Color(0,1,1),0);
break;
case 2:
AtackingSet(2);
CreateLineT(Crystals[0].transform.position, new Color(1,0,0),0);
break;
case 3:
AtackingSet(3);
CreateLineT(Crystals[4].transform.position, new Color(0.5f,0,1),0);
break;
case 4:
ShootAtack(UnityEngine.Random.Range(5,9), false);
break;
case 5:
ShootAtack(UnityEngine.Random.Range(5,9),true);
break;
case 6:
ShootAtack(UnityEngine.Random.Range(0,5),false);
break;
case 7:
AtackingSet(4);
CreateLineT(Crystals[1].transform.position, new Color(0.5f,0,1),0);
break;
print(inda);
}
}
void AtackingSet(int i)
{
switch(i )
{
case <4:
List<int> LI = new List<int>{1,2,0,4};
Vector3 pos = new Vector3(UnityEngine.Random.Range(-30,30), 0,0);
RayAtack(i, pos);
List<Color> col = new List<Color> {new Color(1,0,0), new Color(0,1,1), new Color(1,0,0), new Color(0.5f,0,1)};
CreateLineT(pos, col[i], LI[i]);
break;
case 4:
pos = new Vector3(UnityEngine.Random.Range(-30,30), -5,0);
RayAtack(5, pos);
col = new List<Color> {new Color(1,0,0), new Color(0,1,1), new Color(1,0,0), new Color(0.5f,0,1)};
CreateLineT(pos, col[0], 1);
break;
}
}
void ShootAtack(int i, bool Heal)
{
try
{
Vector3 diference;
float rotateZ;
Rigidbody2D rb = GetComponent<Rigidbody2D>();
GameObject Crys;
switch(i)
{
case >4 :
if (Heal)
{
Crys = Instantiate(Attacks[5], Crystals[i].transform.position, new Quaternion(0,0,0,0));
}else
{
Crys = Instantiate(Attacks[4], Crystals[i].transform.position, new Quaternion(0,0,0,0));
}
List<Color> col ;
diference = GameObject.Find("player").transform.position - Crys.transform.position;
rotateZ = Mathf.Atan2(diference.y, diference.x) * Mathf.Rad2Deg;
Crys.transform.rotation = Quaternion.Euler(0f, 0f, (rotateZ) -90);
Crys.GetComponent<Rigidbody2D>().linearVelocity = (GameObject.Find("player").transform.position - Crys.transform.position).normalized * 10;
break;
case 1:
Crys = Instantiate(Attacks[9], Crystals[3].transform.position, new Quaternion(0,0,0,0));
diference = GameObject.Find("player").transform.position - Crys.transform.position;
rotateZ = Mathf.Atan2(diference.y, diference.x) * Mathf.Rad2Deg;
Crys.transform.rotation = Quaternion.Euler(0f, 0f, (rotateZ) -90);
Crys.GetComponent<Rigidbody2D>().linearVelocity = (GameObject.Find("player").transform.position - Crys.transform.position).normalized * 10;
break;
case 2:
Crys = Instantiate(Attacks[10], Crystals[i].transform.position, new Quaternion(0,0,0,0));
diference = GameObject.Find("player").transform.position - Crys.transform.position;
rotateZ = Mathf.Atan2(diference.y, diference.x) * Mathf.Rad2Deg;
Crys.transform.rotation = Quaternion.Euler(0f, 0f, (rotateZ) -180);
Crys.GetComponent<Rigidbody2D>().linearVelocity = (GameObject.Find("player").transform.position - Crys.transform.position).normalized * 10;
break;
case 3:
Crys = Instantiate(Attacks[7], Crystals[i].transform.position, new Quaternion(0,0,0,0));
diference = GameObject.Find("player").transform.position - Crys.transform.position;
rotateZ = Mathf.Atan2(diference.y, diference.x) * Mathf.Rad2Deg;
Crys.transform.rotation = Quaternion.Euler(0f, 0f, (rotateZ) );
Crys.GetComponent<Rigidbody2D>().linearVelocity = (GameObject.Find("player").transform.position - Crys.transform.position).normalized * 10;
break;
case 4:
Crys = Instantiate(Attacks[6], Crystals[i].transform.position, new Quaternion(0,0,0,0));
diference = GameObject.Find("player").transform.position - Crys.transform.position;
rotateZ = Mathf.Atan2(diference.y, diference.x) * Mathf.Rad2Deg;
Crys.transform.rotation = Quaternion.Euler(0f, 0f, (rotateZ) - 90);
Crys.GetComponent<Rigidbody2D>().linearVelocity = (GameObject.Find("player").transform.position - Crys.transform.position).normalized * 10;
break;
case 0 :
Crys = Instantiate(Attacks[5], Crystals[0].transform.position, new Quaternion(0,0,0,0));
diference = GameObject.Find("player").transform.position - Crys.transform.position;
rotateZ = Mathf.Atan2(diference.y, diference.x) * Mathf.Rad2Deg;
Crys.transform.rotation = Quaternion.Euler(0f, 0f, (rotateZ) -90);
Crys.GetComponent<Rigidbody2D>().linearVelocity = (GameObject.Find("player").transform.position - Crys.transform.position).normalized * 10;
break;
}}
catch{print($"Crystal{i} is broken"); Atacking();}
}
void RayAtack(int i, Vector3 pos)
{try{
switch(i)
{
case 0:
Instantiate(Attacks[0], pos, new Quaternion(0,0,0,0));
CreateLineT(Crystals[1].transform.position, new Color(1,0,0),0);
break;
case 1:
Instantiate(Attacks[1], pos, new Quaternion(0,0,0,0));
CreateLineT(Crystals[2].transform.position, new Color(0,1,1),0);
break;
case 2:
Instantiate(Attacks[2], pos, new Quaternion(0,0,0,0));
CreateLineT(Crystals[0].transform.position, new Color(1,1,1),0);
break;
case 3:
Instantiate(Attacks[3], pos, new Quaternion(0,0,0,0));
CreateLineT(Crystals[4].transform.position, new Color(0.5f,0,1),0);
break;
case 5:
Instantiate(Attacks[8], pos, new Quaternion(0,0,0,0));
CreateLineT(Crystals[1].transform.position, new Color(1,0,0),0);
break;
}
}
catch{print($"Crystal{i} is broken"); Atacking();}
}
void CreateLineT(Vector3 pos, Color col, int CrystalNum)
{
GameObject NL = Instantiate(Liner);
LineRenderer NLR = NL.GetComponent<LineRenderer>();
NLR.SetPosition(0, new Vector3(Crystals[CrystalNum].transform.position.x, Crystals[CrystalNum].transform.position.y, Crystals[CrystalNum].transform.position.z ));
NLR.SetPosition(1,pos);
NLR.startColor = col;
NLR.endColor = col;
}
void Dest(int ToDest)
{
Destroy(Rayss[ToDest]);
}
}