using System.Collections; using System.Collections.Generic; using UnityEngine; class Autoandmed{ public GameObject auto; public int seisund=0; } public class Foor : MonoBehaviour { GameObject[] fooritykid=new GameObject[4]; int[,] seisundid={ {1,0,0}, {1,1,0}, {0,0,1}, {0,0,0}, {0,0,1}, {0,1,0} }; Color[] toonid={Color.red, Color.yellow, Color.green}; float[] ajahetked={5, 6, 9,10, 11, 12}; float aeg=0; List autod=new List(); float minz=-10, maxz=20, minx=-2, maxx=2; const float autosamm=0.05f; Vector3[] liikumisvektorid={new Vector3(0, 0, autosamm), new Vector3(-autosamm, 0, 0), new Vector3(0, 0, -autosamm), new Vector3(autosamm, 0, 0)}; void Start() { fooritykid[0]=GameObject.CreatePrimitive(PrimitiveType.Sphere); fooritykid[0].transform.position=new Vector3(0, 4, 0); fooritykid[1]=GameObject.CreatePrimitive(PrimitiveType.Sphere); fooritykid[1].transform.position=new Vector3(0, 3, 0); fooritykid[2]=GameObject.CreatePrimitive(PrimitiveType.Sphere); fooritykid[2].transform.position=new Vector3(0, 2, 0); fooritykid[3]=GameObject.CreatePrimitive(PrimitiveType.Cylinder); fooritykid[3].transform.position=new Vector3(0, 1, 0); fooritykid[3].transform.localScale=new Vector3(0.5f, 2, 0.5f); fooritykid[0].GetComponent().material.color=Color.red; kuvaSeisund(0); Autoandmed a=new Autoandmed(); a.auto=GameObject.CreatePrimitive(PrimitiveType.Cube); a.auto.transform.position=new Vector3(1, 0, -2); autod.Add(a); } void seisundiKontroll(Autoandmed a){ if(a.seisund==0 && a.auto.transform.position.z>maxz){a.seisund=1;} if(a.seisund==1 && a.auto.transform.position.xmaxx){a.seisund=0;} } void liiguta(){ for(int i=0; i-2 && auto1.transform.position.z<-2+2*autosamm){ if(!(seisundiNr()>=2 && seisundiNr()<=4)){ liigu=false; } } if(liigu){ auto1.transform.position+=new Vector3(0, 0, autosamm); } } else { autoseisund1=1; } } if(autoseisund1==1){ if(auto1.transform.position.x>minx){ auto1.transform.position-=new Vector3(autosamm, 0, 0); } else { autoseisund1=2; } } if(autoseisund1==2){ if(auto1.transform.position.z>minz){ auto1.transform.position+=new Vector3(0, 0, -autosamm); } else { autoseisund1=3; } } if(autoseisund1==3){ if(auto1.transform.position.x().material.color=toonid[i]; } else { fooritykid[i].GetComponent().material.color=Color.black; } } } int seisundiNr(){ int snr=0; for(int anr=0; anrajahetked[anr]){ snr=anr+1; } } return snr; } void Update() { aeg+=Time.deltaTime; if(aeg>ajahetked[ajahetked.Length-1]){aeg-=ajahetked[ajahetked.Length-1];} kuvaSeisund(seisundiNr()); // liigutaAutot(); liiguta(); } }