Merge pull request #9 from playmaker1210/sideObjects

module3
This commit was merged in pull request #9.
This commit is contained in:
playmaker1210
2023-05-13 15:31:56 +02:00
committed by GitHub
11 changed files with 1028 additions and 65 deletions

View File

@@ -11,11 +11,12 @@ public class GroundController : MonoBehaviour
public Material[] materials;
public int materialIndex = 0;
public float groundMoveSpeed = 10f;
private Vector3 lastSideObjectPos = new Vector3(0,0,0);
private Vector3 lastSideObjectPos = new Vector3(0, 0, 0);
//private CollectibleSpawner cs;
private void Awake() {
private void Awake()
{
//cs = FindObjectOfType<CollectibleSpawner>();
//Loading modules
@@ -26,40 +27,56 @@ public class GroundController : MonoBehaviour
//getting all of the ground objects by the tag
ground = GameObject.FindGameObjectsWithTag("Ground");
if(ground.Length == 0){
if (ground.Length == 0)
{
Debug.Log("Nem talalt ground objectet");
}else{
}
else
{
Debug.Log("ground length: " + ground.Length);
}
}
private void Update() {
private void Move(GameObject move)
{
move.transform.position = move.transform.position + new Vector3(0, 0, -groundMoveSpeed * Time.deltaTime);
}
private void Update()
{
ground = GameObject.FindGameObjectsWithTag("Ground"); //torles miatt ujra le kell kerni a ground objecteket
sideObjectsSpawned = GameObject.FindGameObjectsWithTag("SideObject");
OrderArrayByZ(ground); //rendezzuk z szerint a talajt
OrderArrayByZ(sideObjectsSpawned);
OrderArrayByZ(sideObjectsSpawned);
if(sideObjectsSpawned.Length > 0){
lastSideObjectPos = sideObjectsSpawned[sideObjectsSpawned.Length-1].transform.position;
for (int i = 0; i < ground.Length; i++)
{ //ground objecteket mozgatja
//ground[i].transform.position = ground[i].transform.position + new Vector3(0,0, -groundMoveSpeed * Time.deltaTime);
Move(ground[i]);
}
for (int i = 0; i < ground.Length; i++){ //ground objecteket mozgatja
ground[i].transform.position = ground[i].transform.position + new Vector3(0,0, -groundMoveSpeed * Time.deltaTime);
}
for(int i = 0; i < sideObjectsSpawned.Length; i++){
sideObjectsSpawned[i].transform.position = sideObjectsSpawned[i].transform.position + new Vector3(0,0, -groundMoveSpeed * Time.deltaTime);
}
for (int i = 0; i < sideObjectsSpawned.Length; i++)
{
//sideObjectsSpawned[i].transform.position = sideObjectsSpawned[i].transform.position + new Vector3(0,0, -groundMoveSpeed * Time.deltaTime);
Move(sideObjectsSpawned[i]);
}
//uj ground letrehozas
if(ground[ground.Length-1].transform.position.z <= 120){
if (ground[ground.Length - 1].transform.position.z <= 120)
{
CreateNewGround();
CreateNewSideObjects(false);
for (int k = 0; k < 3; k++)
{
CreateNewSideObjects(false);
CreateNewSideObjects(true);
}
ground = GameObject.FindGameObjectsWithTag("Ground");
for(int i = 0; i < ground.Length; i++){
for (int i = 0; i < ground.Length; i++)
{
/*foreach (GameObject child in ground[i].transform){
if (child.name == "Lane1" || child.name == "Lane2" || child.name == "Lane3"){
Debug.Log(child.name + " " + transform.gameObject.name);
@@ -70,13 +87,13 @@ public class GroundController : MonoBehaviour
lanes[1] = ground[i].transform.Find("Lane2");
lanes[2] = ground[i].transform.Find("Lane3");
foreach(var item in lanes){
foreach (var item in lanes)
{
item.GetComponent<MeshRenderer>().material = materials[materialIndex];
}
}
}
}
}
//ellenorzi hogy torolheto e az object || mar nem szukseges mert van egy trigger box
/*foreach (var item in ground){
if(CheckGroundToDestroy(item)){
@@ -87,36 +104,89 @@ public class GroundController : MonoBehaviour
//cs.SpawnCoin();
}
private GameObject[] LoadPrefabs(string path){ //toltese be a palya objecteket a resources mappabol pl: "Prefabs/Modulok"
private GameObject[] LoadPrefabs(string path)
{ //toltese be a palya objecteket a resources mappabol pl: "Prefabs/Modulok"
GameObject[] arr = Resources.LoadAll<GameObject>(path);
return arr;
}
private void CreateNewSideObjects(bool isLeftSide){
int random = UnityEngine.Random.Range(0, sideObjects.Length);
private void CreateNewSideObjects(bool isLeftSide)
{
List<GameObject> side = new List<GameObject>(); //eltarolja egy oldal sideObjectjeit, hogy a jo oldalhoz nezze a kovetkezo elemet;
GameObject inst = sideObjects[random];
Vector3 pos = new Vector3(0,0,0);
if(inst.name == "haz1" && !isLeftSide){
pos = new Vector3(4,0,0); //check pos in editor TODO!!
}else if(inst.name == "haz2"){
pos = new Vector3(9,0,0);
foreach (var item in sideObjectsSpawned)
{
if (item.transform.position.x < 0 && isLeftSide)
{
side.Add(item); //ball oldal
}
else
{
side.Add(item); //jobb oldal
}
}
if(isLeftSide) pos.x = -pos.x;
int random = UnityEngine.Random.Range(0, sideObjects.Length);
random = 0; //csak debug
Instantiate(inst, lastSideObjectPos + pos, ground[0].transform.rotation);
GameObject inst = sideObjects[random];
//remake to get width
Vector3 offset = new Vector3(0, 0, 10f);
if (sideObjectsSpawned.Length > 0)
{
if (sideObjectsSpawned[sideObjectsSpawned.Length - 1].gameObject.name.Contains("haz1")) //haz1Clone
offset = new Vector3(0, 0, 10f); //TODO adjust
else if (sideObjectsSpawned[sideObjectsSpawned.Length - 1].gameObject.name.Contains("haz2"))
offset = new Vector3(0, 0, 20f); //TODO adjust
}
//
Vector3 pos = new Vector3(9f, 0, 0);
if (sideObjectsSpawned.Length > 0)
pos = sideObjectsSpawned[sideObjectsSpawned.Length - 1].transform.position + offset;
else
pos = pos + offset;
if (isLeftSide) pos.x = -pos.x;
Instantiate(inst, pos, inst.transform.rotation);
sideObjectsSpawned = GameObject.FindGameObjectsWithTag("SideObject");
OrderArrayByZ(sideObjectsSpawned);
}
public void changeMaterialIndex(){
public void changeMaterialIndex()
{
int materialteszt;
bool teszteljtovabb = true;
while (teszteljtovabb == true)
{
materialteszt = UnityEngine.Random.Range(0, materials.Length);
Debug.Log(materialteszt);
if (materialteszt == materialIndex)
{
}
else
{
materialIndex = materialteszt;
teszteljtovabb = false;
}
}
teszteljtovabb = true;
}
private bool CheckGroundToDestroy(GameObject toCheck){
private bool CheckGroundToDestroy(GameObject toCheck)
{
//z = -80 -nal lehet torolni
if(toCheck.transform.position.z <= -80){
if (toCheck.transform.position.z <= -80)
{
Debug.Log("elerte " + toCheck.name);
return true; //torolheto
}
@@ -124,22 +194,27 @@ public class GroundController : MonoBehaviour
return false; //nem torolheto
}
private void OrderArrayByZ(GameObject[] array){
private void OrderArrayByZ(GameObject[] array)
{
GameObject csere;
for (int i = 0; i < array.Length; i++){
for(int j = 0; j < i; j++){
if(array[j].transform.position.z > array[j+1].transform.position.z){
for (int i = 0; i < array.Length; i++)
{
for (int j = 0; j < i; j++)
{
if (array[j].transform.position.z > array[j + 1].transform.position.z)
{
csere = array[j];
array[j] = array[j+1];
array[j+1] = csere;
array[j] = array[j + 1];
array[j + 1] = csere;
}
}
}
}
private void CreateNewGround(){
private void CreateNewGround()
{
int random = UnityEngine.Random.Range(0, loadFrom.Length);
//egy modullal elobb tolt be, annak az iranyanak megfeleloen, +80 a ket modul hossza
Instantiate(loadFrom[random], new Vector3(0,0, ground[ground.Length-1].transform.position.z + 40), ground[ground.Length-1].transform.rotation);
Instantiate(loadFrom[random], new Vector3(0, 0, ground[ground.Length - 1].transform.position.z + 40), ground[ground.Length - 1].transform.rotation);
}
}

19
Assets/Scripts/portal.cs Normal file
View File

@@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class portal : MonoBehaviour
{
private GroundController gc;
// Start is called before the first frame update
void Awake()
{
gc = FindObjectOfType<GroundController>();
}
private void OnTriggerEnter(Collider other)
{
gc.changeMaterialIndex();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d60fcfdeb5dfdfd4a9f8ba42c2ee9d63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: