This commit is contained in:
2023-05-29 15:36:27 +02:00
parent 282faea747
commit 0042241f56
5 changed files with 240 additions and 136 deletions

View File

@@ -19,6 +19,8 @@ public class GroundController : MonoBehaviour
//private CollectibleSpawner cs;
private Material newMaterial;
private void Awake()
{
//cs = FindObjectOfType<CollectibleSpawner>();
@@ -39,6 +41,8 @@ public class GroundController : MonoBehaviour
{
Debug.Log("ground length: " + ground.Length);
}
newMaterial = materials[0];
}
private void Move(GameObject move)
@@ -74,27 +78,19 @@ public class GroundController : MonoBehaviour
//uj ground letrehozas
if (ground[ground.Length - 1].transform.position.z <= 120)
{
if(groundCounter == portalSpawnNumber){
if (groundCounter == portalSpawnNumber)
{
CreateNewGround(true);
groundCounter = 0; //ne menjen a vegtelensegig a counter
}else{
}
else
{
CreateNewGround();
}
ground = GameObject.FindGameObjectsWithTag("Ground");
for (int i = 0; i < ground.Length; i++)
{
Transform[] lanes = new Transform[3];
lanes[0] = ground[i].transform.Find("Lane1");
lanes[1] = ground[i].transform.Find("Lane2");
lanes[2] = ground[i].transform.Find("Lane3");
foreach (var item in lanes)
{
item.GetComponent<MeshRenderer>().material = materials[materialIndex];
}
}
ModuleColorChange();
}
//cs.SpawnCoin();
@@ -152,7 +148,7 @@ public class GroundController : MonoBehaviour
if (isLeftSide && pos.x > 0) //x negativ hogy a bal oldalra keruljon
pos.x = -pos.x;
Instantiate(inst, pos, rotation);
@@ -160,6 +156,22 @@ public class GroundController : MonoBehaviour
OrderArrayByZ(sideObjectsSpawned);
}
public void ModuleColorChange()
{
for (int i = 0; i < ground.Length; i++)
{
Transform[] lanes = new Transform[3];
lanes[0] = ground[i].transform.Find("Lane1");
lanes[1] = ground[i].transform.Find("Lane2");
lanes[2] = ground[i].transform.Find("Lane3");
foreach (var item in lanes)
{
item.GetComponent<MeshRenderer>().material = newMaterial;
}
}
}
public void changeMaterialIndex()
{
int materialteszt;
@@ -184,6 +196,11 @@ public class GroundController : MonoBehaviour
teszteljtovabb = true;
}
public void ChangeMaterial(Material mat)
{
newMaterial = mat;
}
private bool CheckGroundToDestroy(GameObject toCheck)
{
//z = -80 -nal lehet torolni
@@ -219,12 +236,12 @@ public class GroundController : MonoBehaviour
GameObject inst;
if(!portalModulSpawn)
if (!portalModulSpawn)
inst = loadFrom[random];
else
inst = portalModul;
//egy modullal elobb tolt be, annak az iranyanak megfeleloen, +80 a ket modul hossza
Instantiate(inst, new Vector3(ground[ground.Length - 1].transform.position.x, ground[ground.Length - 1].transform.position.y, ground[ground.Length - 1].transform.position.z + 40), ground[ground.Length - 1].transform.rotation);
groundCounter++;

View File

@@ -5,20 +5,22 @@ using UnityEngine;
public class portal : MonoBehaviour
{
private GroundController gc;
// Start is called before the first frame update
private int random;
void Awake()
{
gc = FindObjectOfType<GroundController>();
random = UnityEngine.Random.Range(0, gc.materials.Length);
gameObject.GetComponent<MeshRenderer>().material = gc.materials[gc.materialIndex];
gameObject.GetComponent<MeshRenderer>().material = gc.materials[random];
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag.Equals("Player")){
gc.changeMaterialIndex();
gc.ChangeMaterial(gc.materials[random]);
gc.ModuleColorChange();
}
}