ãã®èšäºã§ã¯ãçæéã§ãããªã²ãŒã ãéçºããèå³æ·±ããå°ãèªæã§ãªãç¬éã«ã€ããŠèª¬æããŸãã競æã®èŠåã«åŸã£ãŠãå®è¡å¯èœãªãã¢ã1é±é以å
ã«ããªãªãŒã¹ã2é±é以å
ã«æåºããå¿
èŠããããŸãã ãã®èšäºã¯ããã§ã«Unity3Dã§éãã§ãããããã®ã²ãŒã ãšã³ãžã³ã§HelloWorldããããããžã§ã¯ããé£ããããŠããªã人ã察象ãšããŠããŸãã
泚ç®ãéããç»å-ã²ãŒã ã®ã¹ã¯ãªãŒã³ã·ã§ããã
ã²ãŒã ã®ã¢ã€ãã¢ãã³ã³ã»ãã
ã²ãŒã ã倧奜ãã§ãã çŸè±¡ã®ããã«ã ãŸãããããªã²ãŒã ã®éçºã¯ãããã°ã©ãã³ã°ãæ°åŠãã¢ãŒãã®éåžžã«èå³æ·±ãçµã¿åããã§ãã æ®å¿µãªãããã²ãŒã éçºããã»ã¹ãæ倧éã«åæ¥çã«æåãããããã«ååãªæéãšãªãœãŒã¹ãè²»ããäœè£ã¯ãŸã ãããŸãããã²ãŒã äœæããã»ã¹ã倧å¹
ã«ç°¡çŽ åãããŠããã«ãããããããæºåž¯é»è©±ã®å€ããå°ãªããå
šäœçãªã²ãŒã ã¯2æ¥éã®ãããã€ããã泚æãå°ãªãããšãçµéšããããã£ãŠããŸã-3ã4幎åã
ãã ãã2é±éã®ã²ãŒã ã®ç«¶äºããããéèŠãå°ãªãå Žåã¯ãããã§è©Šãããšãã§ããŸãã
éçºã®æåã®æ®µéã§ã¯ãã²ãŒã ã®ã³ã³ã»ãããéžæããå¿
èŠããããŸãã ãžã£ã³ã«ãã²ãŒã ãã¬ã€ãé¢é£ã²ãŒã ã¯ãæ¢åã®ã²ãŒã ãããåªããŠããŸãã ãããŠãçŸæç¹ã§æãéèŠãªããšã¯ãããªãã®åŒ·ããé倧è©äŸ¡ããªãããšã§ãããªããªããã«ãŒã«ã¯æéã®é¢ã§éåžžã«å³æ Œã§ããã競äºãšã¯å¥ã«ãããªãã®èœåãšããŒã ã®èœåãé©åã«è©äŸ¡ããããšãéåžžã«éèŠã§ã-ãããªããã°ãéçºãé
ããç±æã倱ãããå¯èœæ§ããããŸã
ãã®å Žåãç§ã¯ããªãåçŽãªãžã£ã³ã«ãéžæããŸãã-ããã¯ïŒã¹ã©ãã·ã¥èŠçŽ ãåãããããããã¥ãŒã®ã¢ãŒã±ãŒãã§ãã ç§ã¯æ¬¡ã®ã²ãŒã ã«è§ŠçºãããŸããïŒå€ãã®äººããããããã¬ã€ããèŠããããŠãªã«ãããªãã¿ã ã£ããšæããŸãïŒïŒ
æã®å£ïŒç©Žç§ã®ãæ°ã«å
¥ãã®ããŒã°ã«ã®1ã€ã§ãããããŒã°ã®ãããªãžã£ã³ã«ã®ã¿ãŒã³ããŒã¹ã®ã²ãŒã ïŒéåžžã«ã·ã³ãã«ã§ãããåæã«åºæ¿çã§ãã ãã®ã²ãŒã ãããçæãããã©ããªã³ã¹ãšæµã®ã©ã³ãã ãªã¹ããŒã³ã®ã¢ã€ãã¢ãåããŸããã
ã¯ãªã ãŸã³ã©ã³ãããããã¥ãŒã®ã¢ãŒã±ãŒãã ãã®ã²ãŒã ãããç§ã¯æµãšãã€ããã¯ã¹ã®æ°ãåããŸããã
ãã®çµæãç§ã¯æ¬¡ã®ã²ãŒã ãã¬ã€ã«è¡ããŸããïŒãã¬ã€ã€ãŒã¯ããã£ã©ã¯ã¿ãŒãå¶åŸ¡ããè¿·è·¯ãé§ãæããæµãæã¡ããã¯ãŒã¢ãããåéããã¬ãã«ç°å¢ãšå¯Ÿè©±ããããŒãæ¢ããŠæ¬¡ã®ã¬ãã«ã«ç§»åããŸããæµã¯ããåå£ã§è¿·è·¯ã¯ããæ··ä¹±ããŠããŸãã éçºç°å¢ãããŒã«ããã©ãããã©ãŒã ã®éžæã
äœããéžæã§ããŸããïŒ èšå€§ãªæ°ã®ã²ãŒã ããã³ã°ã©ãã£ãã¯ãšã³ãžã³ããããŸãããçŸæç¹ã§æã人æ°ãããã®ã¯Unity3DãUnrealEngine4ãcocos2dãlibGDXã§ãã æåã®2ã€ã¯äž»ã«ãã¹ã¯ãããã®ãè€éãªãã²ãŒã ã«äœ¿çšãããæåŸã®2ã€ã¯æºåž¯é»è©±çšã®åçŽãª2次å
ã²ãŒã ã«äœ¿çšãããŸãã ãŸããåçŽãªã²ãŒã ã«ã¯ãããŠã¹æåã®ãã¶ã€ããŒãããŸãã
ç§ã¯C ++ã®ç±ççãã¡ã³ã§ããããã®èšèªãç¡éã«æããŠãããšããäºå®ã«ããããããããã®èšèªã¯2é±éã§ã²ãŒã ãæžããã®ã§ã¯ãªãããšãèªèããŠããŸãã Unity3Dã¯ãCïŒãJSãããã³ç¬èªã®Pythonã®ãããªèšèªã®Booã¹ã¯ãªããã§ã¹ã¯ãªãããèšè¿°ããæ©èœãæäŸããŸãã ã»ãšãã©ã®ããã°ã©ãã¯ãæãããªçç±ã§CïŒã䜿çšããŸãã ã¯ããç§ã¯æèŠã®ã¬ãã«ã§Unityã奜ãã§ããã
éçºãã¢ãŒããã¯ãã£ãèå³æ·±ãç¹
ã¬ãã«
ã²ãŒã ã«ã¯è¿·è·¯ãèµ°ãå¿
èŠããããè¿·è·¯ãçæããå¿
èŠããããŸãã æåã¯èªåã§ã¢ã«ãŽãªãºã ãèãåºãããšã«ããŸãããäžèŠç°¡åããã«èŠããŸããããã£ãŒã«ããæ°Žå¹³ãŸãã¯åçŽã«2ã€ã®çãããªãéšåã«åå²ããããéšåããå¥ã®éšåãžã®éè·¯ãäœæããŸãã 次ã«ãå·Šå³ã®ã島ãã«æ²¿ã£ãŠååž°çã«æ©ããåãããã«åŠçããŸãããµã€ãºãèš±ãå Žåã¯2ã€ã®éšåã«åããèš±ããªãå Žåã¯ãã®ãŸãŸéšå±ããåºãŸãã
ããããéšå±ããä»ã®å ŽæãŸã§ã1ã€ã®åäžã®ãã¹ããã©ãããšãã§ããŸãã ããã¯ããã®è¿·è·¯ã®ç 究ã«èå³ããããšãã芳ç¹ããã¯ããŸãæ£ãããããŸãããè¿·è·¯èªäœã¯ãç§ãå®æ°ãã©ã®ããã«èª¿æŽãããšããŠãããã·ã¢ã®å¯å®€ã建ãŠãã®ã«ãããã䌌ãã现é·ãçãéšå±ã«åããåŸåãæã€æçœãªæ£æ¹åœ¢ã®ãã¹ãã®å€èŠ³ãæããŠããŸããã æ®å¿µãªãããã¢ã«ãŽãªãºã ã®å
ã®ããŒãžã§ã³ã¯ä¿åãããããã®çµæã衚瀺ã§ããŸããã
å
ã®ã©ããªã³ã¹çæã¢ã«ãŽãªãºã ã®å³ãããããç§ã¯ã€ã³ã¿ãŒãããäžã§çæã¢ã«ãŽãªãºã ãæ¢ãããšã«ããC ++ã§æžãããgamedev.ruãŠã§ããµã€ãã§ãããèŠã€ããŸããã
ã¢ã«ãŽãªãºã ã®æ¬è³ªã¯æ¬¡ã®ãšããã§ãã空ã®ãã£ãŒã«ãã«ç®çã®çªå·ãé
眮ãããŸã-néšå±ã æ°ããéšå±ããšã«ããã®ãµã€ãºã¯æå®ãããå¶éå
ã§ã©ã³ãã ã«èšå®ããããã®åŸãéšå±ã¯ç«¶æå Žã®ã©ã³ãã ãªåº§æšã«é
眮ãããŸãã äœæãããéšå±ã以åã«äœæãããéšå±ãšäº€å·®ããå Žåãã©ã³ãã ãªãµã€ãºã§ã©ã³ãã ãªå Žæã«åäœæããå¿
èŠããããŸãã ã¡ã€ã³ã®m = 100åã®ç¹°ãè¿ãã§éšå±ãèªåèªèº«ã®å ŽæãèŠã€ããããšãã§ããªãå Žåããã£ãŒã«ãã¯æºããããŠãããšèŠãªããã次ã®éšå±ã«é²ã¿ãŸãã
void Generate(int roomsCount) { for (int i = 0; i < roomsCount; i++) { for (int j = 0; j < 100; j++) { int w = Random.Range(3, 10); int h = Random.Range(3, 10); Room room = new Room(); room.x = Random.Range(3, m_width - w - 3); room.y = Random.Range(3, m_height - h - 3); room.w = w; room.h = h; List<Room> inter = rooms.FindAll(room.Intersect); if (inter.Count == 0) { rooms.Add(room); break; } } return; } }
次ã«ãå¿
èŠãªæ°ã®éšå±ãäœæãããããããããéè·¯ã«æ¥ç¶ããå¿
èŠããããŸããäœæããããã¹ãŠã®éšå±ãå·¡åããåŠç察象ã®éšå±ã®äžå¿ããä»ã®éšå±ã®äžå¿ãŸã§ã®ãã¹A *ãèŠã€ããã¢ã«ãŽãªãºã ã䜿çšããŠãã¹ãèšç®ããŸãã ã¢ã«ãŽãªãºã A *ã®å Žåãéšå±ã®ã»ã«ã®éã¿ã1ã«èšå®ãã空ã®ã»ã«ã®éã¿ãkã«èšå®ããŸãã ã¢ã«ãŽãªãºã ã¯äžé£ã®ã»ã«ãæäŸããŸã-éšå±ããéšå±ãžã®ãã¹ããããéæ³ã®ãããšããã§ãïŒkãå¢ãããšãããå°ãªãå»äžã§ããè€éãªè¿·è·¯ãååŸããå¢å ããŸã-è¿·è·¯ãå»äžã§ãã¹ããããããŸãã ãã®å¹æã¯ã空ã®ã»ã«ã®éã¿ã倧ãããªããšããã¹æ€çŽ¢ã¢ã«ãŽãªãºã ãéè·¯ãããã³ããããã®ã§ã¯ãªããéãåãéãããšãè©Šã¿ãããã«éæãããŸãã
void GenerateAllPassages() { foreach (Room r in rooms) { APoint center1 = new APoint(); center1.x = rx + (rw/2); center1.y = ry + (rh/2); center1.cost = 1; foreach (Room r2 in rooms) { APoint center2 = new APoint(); center2.x = r2.x + (r2.w/2); center2.y = r2.y + (r2.h/2); center2.cost = 1; GeneratePassage(center1, center2);
ç·ã®ã¿ã€ã«ã¯ãåéšå±ããåéšå±ãžã®ãã¹ãèŠã€ããçµæã瀺ããŸãã
次ã«ãè¿·è·¯ã®ãè£
食ããå£ã®æ¢çŽ¢ããããŸãã
ã¢ã«ãŽãªãºã ã¯éåžžã«æé©åãããŠããŸãããã©ãããããi7ã§ã¯ã50 * 50ã®è¿·è·¯ã®çæïŒã¬ãã«ãè¡šãã²ãŒã ãªããžã§ã¯ãã®äœæãšäžç·ã«ïŒã«ã¯çŽ10ç§ããããŸãã æ®å¿µãªãããã¬ãã«çæã¢ã«ãŽãªãºã ã®è€éãã倧ãŸãã«æšå®ããããšãã§ããŸãããæ³¢çµè·¯æ¢çŽ¢ã¢ã«ãŽãªãºã ã®è€éãã¯ä¿æ°kã«äŸåããããã§ãã ãããã圌ã¯ç§ã®ã²ãŒã ã§èŠããè¿·è·¯ãæ£ç¢ºã«äœæããŸãã
ããã§ã2次å
é
åã®åœ¢ã®è¿·è·¯ãã§ããŸããã ããããç§ãã¡ã®ã²ãŒã ã¯3次å
ã§ããã3次å
空éã§ãã®è¿·è·¯ãã©ãã«ãããŠäœæããå¿
èŠããããŸãã æãæçœã§ééã£ããªãã·ã§ã³ã¯ãé
åã®åèŠçŽ ïŒãã¥ãŒããŸãã¯ãã¬ãŒã³ïŒã«ã²ãŒã ãªããžã§ã¯ããäœæããããšã§ãã ãã®ã¢ãããŒãã®æ¬ ç¹ã¯ããããã®åãªããžã§ã¯ããã€ãã³ãåŠçã·ã¹ãã ã«çµ±åããããšããäºå®ã§ããã€ãã³ãåŠçã·ã¹ãã ã¯ã1ã€ã®CPUã¹ããªãŒã ã§æ¢ã«åäœãã倧å¹
ã«ãã¬ãŒãããããŸãã ç§ã®ã³ã³ãã¥ãŒã¿ãŒã«å€æ°ã®éšå±ãããã¹ã¯ãªãŒã³ã·ã§ããã®ã·ãŒã³ã¯éåžžã«é
ããŠããŸãã ãã®ã¢ãããŒãã¯ããããªã«ãŒãã«ãããŒã³ãŒã«ãããŒãããããã«èŠãããããããŸãã-ãããããããUnityã¯åãçŽ æã®ããŸããŸãªãªããžã§ã¯ãã§å®ç§ã«åäœããŸãã ããã§ããããã¯ãã䟡å€ããããŸããã
æ£ããã¢ãããŒãã¯ãã¬ãã«ã¿ã€ã«ã®2次å
é
åã«åºã¥ããã¡ãã·ã¥ã§1ã€ã®ãªããžã§ã¯ããäœæããããšã§ãã ã¢ã«ãŽãªãºã ã¯ç°¡åã§ããã¿ã€ã«ããšã«ãã¬ã³ããªã³ã°çšã®2ã€ã®ãžãªã¡ããªäžè§åœ¢ãã³ã©ã€ããŒçšã®2ã€ã®ãžãªã¡ããªäžè§åœ¢ãæç»ãããã€ã³ãã®ãã¯ã¹ãã£åº§æšãèšå®ããŸãã 埮åŠãªç¹ã1ã€ãããŸãã
public void GenerateMesh(Map.Tile [,] m_data, Map.Tile type, float height = 0.0f, float scale = 1.0f) { mesh = GetComponent<MeshFilter> ().mesh; collider = GetComponent<MeshCollider>(); squareCount = 0; int m_width = m_data.GetLength(0); int m_height = m_data.GetLength(1); for (int x = 0; x < m_width; x++) for (int y = 0; y < m_height; y++) { if (m_data[x,y] == type) { newVertices.Add( new Vector3 (x*scale - 0.5f*scale , height , y*scale - 0.5f*scale )); newVertices.Add( new Vector3 (x*scale + 0.5f*scale , height , y*scale - 0.5f*scale)); newVertices.Add( new Vector3 (x*scale + 0.5f*scale , height, y*scale + 0.5f*scale)); newVertices.Add( new Vector3 (x*scale - 0.5f*scale , height, y*scale + 0.5f*scale)); newTriangles.Add(squareCount*4); newTriangles.Add((squareCount*4)+3); newTriangles.Add((squareCount*4)+1); newTriangles.Add((squareCount*4)+1); newTriangles.Add((squareCount*4)+3); newTriangles.Add((squareCount*4)+2); int tileIndex = 0; const int numTiles = 4; tileIndex = Mathf.RoundToInt(Mathf.Sqrt(Random.Range(0, numTiles * numTiles)*1.0f)); int squareSize = Mathf.FloorToInt(Mathf.Sqrt(numTiles)); newUV.Add(new Vector2((tileIndex % squareSize)/squareSize, (tileIndex/squareSize)/squareSize)); newUV.Add(new Vector2(((tileIndex + 1) % squareSize)/squareSize, (tileIndex/squareSize)/squareSize)); newUV.Add(new Vector2(((tileIndex + 1) % squareSize)/ squareSize, (tileIndex / squareSize + 1)/squareSize)); newUV.Add(new Vector2((tileIndex % squareSize)/squareSize, (tileIndex/squareSize + 1)/squareSize)); squareCount++; } } mesh.Clear (); mesh.vertices = newVertices.ToArray(); mesh.triangles = newTriangles.ToArray(); mesh.uv = newUV.ToArray(); mesh.Optimize (); mesh.RecalculateNormals (); Mesh phMesh = mesh; phMesh.RecalculateBounds(); collider.sharedMesh = phMesh; squareCount=0; newVertices.Clear(); newTriangles.Clear(); newUV.Clear(); }
åºã®ãã¯ã¹ãã£ã«ã¯ã4ã€ã®ç°ãªãã¿ã€ã«ã®ã¢ã«ã¿ã䜿çšããŸãã
ãããŠããã®ãããªååžã¯ãäžéšã®ã¿ã€ã«ãããå€ããä»ã®ã¿ã€ã«ãããå°ãªãå Žåã«ããèªç¶ã«èŠããããšã«æ°ä»ããŸããã å®éãå¹³åããŠãåºã®2å¹³æ¹ã¡ãŒãã«ããšã«éã®éªšæ Œã1ã€ã ãæ£åšãããããªãµããã³ãžã§ã³ã¯ãããŸããã
ãã®ãããªäžåäžãªååžãäœæããã«ã¯ã次ã®è¡ã䜿çšããŸãã
tileIndex = Mathf.RoundToInt(Mathf.Sqrt(Random.Range(0, numTiles * numTiles)*1.0f));
ããã¯ã¿ã€ã«ã®æ°ã«æ ¹æ¬çãªäŸåãæäŸããŸãã
次ã«ãéžæããã¿ã€ã«ã®ãã¯ã¹ãã£åº§æšããã¯ã¹ãã£åº§æšã®ãªã¹ãã«èšå®ãããŸãã ãã®ã³ãŒããããã¯ã¯ãã¿ã€ã«ã®æ°ã2ã®çŽ¯ä¹ã«çããã¿ã€ã«ã»ããã§æ©èœããŸãã
çµæã¯KDPVã§èŠãããšãã§ããŸã-ã¿ã€ã«ã«ã¯ãŸã ãžã§ã€ã³ããããããã®ãã¡4ã€ãããªãã«ãããããããéåžžã«èªç¶ãã€èªç¶ã§ãã
ãã®æ®µéã§ã¯ãã¬ãã«ã®ãžãªã¡ããªã¯ãããŸãããæµããã¯ãŒã¢ãããã«ããã·ãŒã³ããã®ä»ã®ã²ãŒã ããžãã¯ãå¿
èŠã«å¿ããŠè¿œå ããŠãã埩掻ãããå¿
èŠããããŸãã
ãããè¡ãã«ã¯ãã¬ãã«ãæ
åœããã·ã³ã°ã«ãã³ãããŒãžã£ãŒãäœæããŸãã ãé©åãªãã·ã³ã°ã«ãã³ãäœæã§ããŸãããã²ãŒã ãã¬ã€ãçŽæ¥è¡ãããã·ãŒã³ã«ãªããžã§ã¯ããããŒãžã£ãŒãªããžã§ã¯ããè¿œå ãããããŒãžã£ãŒãã£ãŒã«ããã°ããŒãã«ã«ããŸããã ãã®ãããªè§£æ±ºçã¯åŠåçã«ééã£ãŠããå¯èœæ§ããããŸãïŒãããŠãã³ãã¥ãŒæã®ã·ã³ã°ã«ãã³ãšåŒã°ããŸãïŒãããã®å©ããåããŠãUnityã«ãããŒãžã£ãŒã®ãã£ãŒã«ããã·ãªã¢ã«åãããªããžã§ã¯ãã€ã³ã¹ãã¯ã¿ãŒããªã¢ã«ã¿ã€ã ã§ç·šéã§ããããã«ããŸããã ããã¯ãã³ãŒãã®ã¬ãã«aã®èšå®ãå€æŽãããããã¯ããã«äŸ¿å©ã§é«éã§ãããã¬ãŒã€ãŒã®é»æºãåããã«ãã©ã³ã¹ããããã°ã§ããŸãã éåžžã«äŸ¿å©ãªæ©èœã§ããããšãã°ããã€ã¢ãã°ãæ
åœããã¯ã©ã¹ã®ãªããžã§ã¯ããäœæããããã«ãè€æ°å䜿çšããŸããã
ã²ãŒã ã¬ãã«ã®ã»ããã¯ãåã¬ãã«ã説æãããªããžã§ã¯ãã®é
åã§ãã ã¬ãã«ã説æããã¯ã©ã¹ã¯æ¬¡ã®ãšããã§ãã
ã¬ãã«ã®äœæã¯æ¬¡ã®ãšããã§ãïŒã¬ãã«ãããŒãžã£ãŒã¯AwakeïŒïŒã¡ãã»ãŒãžãåä¿¡ããã°ããŒãã«å€æ°ã®å€ãèªã¿èŸŒã¿ãŸã-ããŒããããã¬ãã«ã®æ°ïŒæåã¯ãŒãã§ã䞻人å
¬ãè¿·è·¯ã®å¥¥æ·±ãã«ç§»åããã«ã€ããŠå¢å ããŸãïŒãã¬ãã«ã¿ã€ãã®ãªããžã§ã¯ãã®é
åããç®çã®ã¬ãã«ãéžæããŸãã 次ã«ãã¬ãã«ãæç¶ãçã«çæãããïŒçæããã== trueïŒå Žåãè¿·è·¯ã®æ§ç¯ãšè£
食ãéå§ãããŸãã ã©ããªã³ã¹ã®æ§ç¯ã¯ä»¥åã«æ€èšããããã³ã¬ãŒã·ã§ã³ã¯ãã³ã¬ãŒã·ã§ã³ããã³decorationsSizeã®å®è¡ã«ããçºçããŸãã æåã®ããªã²ãŒãã§ã¯ãåŒæ°ããšããªãæé ãè¿œå ããŸããããšãã°ãé段ã®ã¬ãã«ã«è¿œå ããŸãã2çªç®ã®åŒæ°ã§ã¯ãããšãã°ãã¬ãã«ã«ãã¯ãŒã¢ãããè¿œå ããŸãïŒè¿·è·¯ã®å¹³æ¹ã¡ãŒãã«ãããã®ãã¯ãŒã¢ããã®å¯åºŠãç¶æããããã«ãããŒãã¹ã®æ°ã¯æ¯äŸããå¿
èŠããããŸãè¿·è·¯ã®ç·åœ¢ãµã€ãºã®2ä¹ïŒãŸãã¯æµã
次ã®é¢æ°ã¯ãæµã®prafabãšãã®æµã®ééãšãã2ã€ã®ãã£ãŒã«ãã®æ§é ã®é
åã䜿çšããŠãæµãé
眮ããŸãã ããšãã°ãé
åã次ã®å ŽåïŒ
{{Mob1, 5.0f}, {Mob2, 1.0f}}
Mobã¿ã€ãMob1ã¯ãMob2ã®5åã®ç¢ºçã§åºçŸããŸãã ã¢ãã®ã¿ã€ãã®æ°ã¯ä»»æã§ãã
ãã®æ©èœã䜿çšãããšãç¹å®ã®ç¢ºçã§ã©ã³ãã ã«åãã¢ãŒãã£ãã¡ã¯ãããã§ã¹ããæªç¥ã®ããŒã·ã§ã³ã®å¹æãªã©ã«é
眮ã§ããŸãïŒ
次ã«ãçæããããã®ãšããŒãã»ããã«ã€ããŠã¯ããã¬ããã¬ãã«ãã€ã³ã¹ã¿ã³ã¹åããŸãïŒååšããå ŽåïŒã ããŒãã»ããã¬ãã«ã®å Žåãããã¯ããžãªã¡ããªãšæåãå«ãã¬ãã«èªäœã§ãã çæããããã®ã«ã€ããŠã¯ããã€ã¢ãã°ãŸãã¯ã«ããã·ãŒã³ã«ãªããŸãã
ãã£ã©ã¯ã¿ãŒã ã¹ã¯ãªããã çžäºäœçš
Unity3Dã¯CïŒã䜿çšãããšããäºå®ã«ãããããããéåžžã®OOPã§ã¯ãªãããªããžã§ã¯ããã³ã³ããŒãã³ããã€ãã³ãã«åºã¥ãç¬èªã®ãã¿ãŒã³ã§åäœããã¯ãã§ãã
Unityãå®è¡ããããšãããå Žåã¯ããããã®ãšã³ãã£ãã£ãç解ããå¿
èŠããããŸããã²ãŒã ãªããžã§ã¯ãã«ã¯ããã€ãã®ã³ã³ããŒãã³ãããããã³ã³ããŒãã³ãã¯ãªããžã§ã¯ãã®ç¹å®ã®æ©èœãæ
åœããŸãã ã¡ãã»ãŒãžïŒAwakeïŒïŒãStartïŒïŒãUpdateïŒïŒãªã©ã®ãŠãŒã¶ãŒãŸãã¯ãµãŒãã¹ïŒãã²ãŒã ãªããžã§ã¯ãã«éä¿¡ãããåã³ã³ããŒãã³ãã«å°éããŸããåã³ã³ããŒãã³ãã¯é©åãšæãããããã«åŠçããŸãã Unityã«éŠŽæã¿ã®ãããã¿ãŒã³ã¯ãããããçãŸããŸããããšãã°ãå³ã®ããã«ãç¶æ¿ã®ä»£ããã«ãã³ã³ããŒãã³ãã®æ§æã䜿çšãã䟡å€ããããŸãã
ç¹æ§åãšåŒã°ããç¹å®ã®ã¿ã¹ã¯ãå®è¡ããã³ã³ããŒãã³ããæã€ãMobãã¿ã€ãã®ãªããžã§ã¯ãããããŸãã EnemyScriptã³ã³ããŒãã³ãã¯AIãæ
åœããShootïŒVector3ã¿ãŒã²ããïŒã¡ãã»ãŒãžãã²ãŒã ãªããžã§ã¯ãã«éä¿¡ããŠæ®åœ±ããMoveToïŒVector3ã¿ãŒã²ããïŒã¡ãã»ãŒãžããã®ãã€ã³ãã«éä¿¡ããŸãã
ShooterScriptã³ã³ããŒãã³ãã¯ãShootãã¡ãã»ãŒãžãåä¿¡ããŠââèµ·åããMoveScriptã¯MoveToã¡ãã»ãŒãžãåä¿¡ããŸãã ããã§ãããã«äŒŒãMobãäœæããããšããŸãããåäœã®ããžãã¯AIãå€æŽããŸãã ãããè¡ãã«ã¯ã次ã®ããã«ãã³ã³ããŒãã³ããAIã¹ã¯ãªããã®ã»ãã®äœããšåçŽã«çœ®ãæããããšãã§ããŸãã
C ++ã®éåžžã®OOPã§ã¯ã次ã®ããã«ãªããŸãïŒUnityã§ã¯ããããè¡ãã¹ãã§ã¯ãããŸããïŒïŒ
class FooEnemy : public ShooterScript, public MoveScript, public MonoBehaviour { void Update() { MoveScript::Update(); ShooterScript::Update(); Shoot({ 0.0f, 0.0f, 0.0f}); MoveTo({ 0.0f, 0.0f, 0.0f}); } }; class BarEnemy : public ShooterScript, public MoveScript, public MonoBehaviour { void Update() { MoveScript::Update(); ShooterScript::Update(); Shoot{ 1.0f, 1.0f, 1.0f}); MoveTo({ 1.0f, 1.0f, 1.0f}); } };
Unityã§ã¯ãéåžžã«ãŠãŒã¶ãŒãã¬ã³ããªãŒã§ããŠã¹æåã§ããç§ã®æèŠã§ã¯ãæµã®å€æ§æ§ã¯ãããã°ã©ããŒãã®éšåãããã²ãŒã ã®å
容ã®ã»ããå€ãããã§ãã
ç°ãªããªããžã§ã¯ãéã®éä¿¡ãåæ§ã®æ¹æ³ã§çºçããŸãã匟䞞ãªããžã§ã¯ããè¡çªãªãŒããŒãããã¡ãã»ãŒãžãåŠçãããšãè¡çªãããªããžã§ã¯ãã«ããã¡ãŒãžïŒãããŒãïŒãã¡ãã»ãŒãžãéä¿¡ããŸãã 次ã«ããDamage Receiverãã³ã³ããŒãã³ãã¯ãã®ã¡ãã»ãŒãžãåä¿¡ããããããã€ã³ãã®æ°ãæžãããŸããããããã€ã³ãããŒãæªæºã®å Žåãã¡ãã»ãŒãžãOnDeathïŒïŒããéä¿¡ããŸãã
ãããã£ãŠãããŸããŸãªè¡åããšãè€æ°ã®ãã¬ããã®çžæãç²åŸã§ããŸãã
ã©ã€ãããŒ
ãã®ãããžã§ã¯ãã§ã¯ãåå¿è
ããããããŒã®ããã«å€ãã®èå³æ·±ãéèªæãªããªãã¯ã䜿çšããŠããŸããèšäºå
ã®ãã¹ãŠãæ€èšããããšã¯äžå¯èœã§ããããããã®èšäºã§ã¯ã©ã€ãããŒã®ç°¡åãªå®è£
ãæ€èšããŸãã
ãã¹ãŠã®ã²ãŒã ã«ã¯ãHPãå§åããå¿
èŠããã察æŠçžæãããŸããã»ãšãã©ãã¹ãŠã®ã²ãŒã ã«ã¯ã察æŠçžæããHPã奪ãããã«ãšãã«ã®ãŒãããã䜿ãããŒããŒãããŸãã ç§ã®ãœãªã¥ãŒã·ã§ã³ã§ã¯ãç®çã®ã¹ããªããã衚瀺ããã¯ã¯ãããæã€åã²ãŒã ãªããžã§ã¯ãïŒããšãã°ãHealthbarãšåŒã°ããïŒãå¿
èŠã§ãã ãã®ãªããžã§ã¯ãã«ã¯ããã¬ãã¥ãŒã§èŠãããšãã§ãããããªã¢ã«ïŒå·ŠåŽãç·è²ã§å³åŽãèµ€è²ã®æ£æ¹åœ¢ïŒãšå
±ã«ã€ã³ã¹ããŒã«ãããMeshRendererã³ã³ããŒãã³ããå¿
èŠã§ãã
ãŸããçæ³ãæ£ãã衚瀺ããã«ã¯ãã©ã€ãããŒã®ãã¯ã¹ãã£ã«ãã€ã³ãïŒPOINTïŒãã£ã«ã¿ãªã³ã°ãå¿
èŠã§ãã
ã¢ã€ãã¢ã¯æ¬¡ã®ãšããã§ãã氎平軞ã®ã¿ã€ã«ã0.5ã«èšå®ãããšãåè§åœ¢ã¯ç»åã®ååã衚瀺ããŸãã åã軞ã®ãªãã»ããã0ã«èšå®ãããŠããå Žåãæ£æ¹åœ¢ã®å·ŠååïŒç·è²ïŒã衚瀺ããã1ãå³ååã®å Žåãäžéå€ã§ã¯ãã©ã€ãããŒã¯ã©ã€ãããŒã®åäœãšåãããã«åäœããŸãã ç§ã®å Žåãã©ã€ãããŒã®ãã¯ã¹ãã£ã¯2ã€ã®ãã¯ã»ã«ã§æ§æãããŠããŸããããã®ã¡ã³ããŒãã䜿çšãããšãçŸããæäœãã®ã©ã€ãããŒã衚瀺ã§ããŸãã
ã©ã€ãããŒã®ã¹ããŒã¿ã¹ãæŽæ°ããå¿
èŠãããå Žåã«ãæå·ã®åŠçãšè¡šç€ºãè¡ãã³ã³ããŒãã³ãã¯ã次ã®ã³ãŒããå®è¡ããŸãã
ããã衚瀺ããæ¹æ³ã¯ãã¹ããŒããã§ããããã¯ãåçŽè»žã«æ²¿ã£ãŠç§»åããããšã§ãåäœããããã§ãããã®å Žåã4ãã¯ã»ã«ã®ãã¯ã¹ãã£ã䜿çšãããŸããäžéšã¯ã¢ã¯ãã£ãã¹ããªããã«å¯Ÿå¿ããäžéšã¯ããã·ãã§ãïŒããšãã°ããªããŒãäžãæŠåšã®éç±ãŸãã¯éè¡åž«ã®éåŽïŒ ã
ãŸãšã
æ®å¿µãªãããç§ã¯åå è
ãªã¹ãã®äžå€®ã§æ¥ãã¹ãå Žæãåã£ãŠã競äºã«è² ããŸããã
ç§ã®æèŠã§ã¯ããšã©ãŒã¯ããã§ããããããããªã³ã³ãã³ãã§ãã ç空ã®ç圢ã¹ã±ãŒã©ããªãã£ã®èšèšã«å€ãã®æéãè²»ãããŠããã®ã§ã競äºã®æåŸãã2çªç®ã®æ¥ã«ãã²ãŒã ã«ã³ã³ãã³ãããŸã£ãããªãããšã«æ°ä»ããŸããã ã¬ãã«ããããããã¹ãã©ã€ããæµãããŒãã¹ãªã©ã ã²ãŒã ã®äž»äººå
¬ãšããŠãç¬ãã®ããã«ãã¬ãŒã¹ãã«ããŒãæ¿å
¥ããŸãã ãã®çµæãã²ãŒã ã¯10åéãããŸããŸãªæµãšã²ãŒã ã®éçºã®å¯èœæ§ãæã¡ãªããããæŽå²ãã°ã©ãã£ãã¯ããªããããããããŠå
æ°ãªã²ãŒã ãã¬ã€ã«ãªããŸããã 空ã®ã¹ããŒã¹ã«åè§ããã©ãããã©ãŒã ãåãäžãããããŒãã¬ãã«ã¯ããã¬ã€ã€ãŒã«ã²ãŒã ãæªå å·¥ã§æªå®æã§ããããšãå³åº§ã«ç¥ãããŸãã ããã¯ã競äºã§å¿
èŠãšããããã®ã§ã¯ãããŸããã§ããã 審æ»å¡ã¯ãã²ãŒã ããã¬ã€ããã®ã§ã¯ãªããã¹ããŒãªãŒãèªã¿ããã¯ã»ã«ã¢ãŒãã調ã¹ãé³æ¥œãèŽãããšãæãã§ããŸããã
Unity3dã¯è³ç£ã«é¢ãããã®ã§ãã ãã¡ãããç§ã¯èªè»¢è»ã®éçºã«ãã£ãšèå³ããããŸãããç§ã¯ãããããŸãã-åäžã®è³ç£ã䜿çšãããã¹ã¯ãªãããšãªãœãŒã¹ã¯ãã¹ãŠç§ã®ãã®ã§ããã ãã ããäœæ¥ãçµæã§ã¯ãªããå©çã«åããããŠããå Žåã¯ããããè¡ãå¿
èŠã¯ãããŸããã
äžè¬çã«ãæåã¯ç§ã®æ
ç±çãªããã·ã¥ã«ãããã圱é¿ãäžããŸããã å°ããªã©ãã¯ã¹ããŠããããããžã§ã¯ããæ°ããå€èŠ³ã§èŠãå¿
èŠããããŸãããããžã§ã¯ãã®ç±æãšå±æãèŠã€ããã°ãå€åãããå®æãããŠãç·ã®å
ã«ç
§ããã§ãããã ããã§ãªããã°ããœãŒã¹ããªãŒãã³ã¢ã¯ã»ã¹ã§æçš¿ããè¿·è·¯ã®äœæãªã©ã®èå³æ·±ããã€ã³ããUnity Storeã®ææã¢ã»ããã®åœ¢ã§äœæããŸãã
ãã®èšäºãèå³æ·±ããæçã§ãã£ãããšãé¡ã£ãŠããŸãã
PSïŒ
ãã®ãªã³ã¯ããããŠã³ããŒãããããšã§ãã²ãŒã ã«æ
£ããããšãã§ããŸãã
ãŸãã¯ã
ããã®Yandexãã©ãŠã¶
㧠ã