예제 #1
0
 // public void LoseFood (int loss){
 //  animator.SetTrigger("playerHit");
 //  food = food - loss;
 //  foodText.text = "-" + loss + " | Food: "+ food;
 // }
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Exit")
     {
         // Invoke("Restart",restartLevelDelay);
         // enabled = false;
         // Debug.Log("Reached the stairs, gz!");
     }
     else if (other.tag == "Enemy")
     {
         Debug.Log("Enemy! lookout");
     }
     else if (other.tag == "question")
     {
         questionTrigger qt = other.GetComponent <questionTrigger>();
         Debug.Log(" question: " + qt.questionID);
         SceneManager.LoadScene("questionScne", LoadSceneMode.Additive);
     }
     else if (other.tag == "info")
     {
         infoTrigger it = other.GetComponent <infoTrigger>();
         Debug.Log(" info: " + it.infoID);
     }
 }
예제 #2
0
    void BoardSetup()
    {
        // mapManager.initMapData();
        boardHolder = new GameObject("Board").transform;
        mapManager  = new MapManager();
        int _col = 0;
        int _row = 0;

        mapGrid = mapManager.initMapData();
        int questionCounter = 0;
        int infoCounter     = 0;

        for (int i = mapGrid.Count - 1; i > -1; i--)
        {
            for (int z = 0; z < mapGrid[i].Count; z++)
            {
                // full generation
                int tileIdentity = (int)mapGrid[i][z].x;
                int nodeContent  = (int)mapGrid[i][z].y;
                int tileContent  = (int)mapGrid[i][z].z;
                if (tileIdentity != 0)
                {
                    GameObject toInstantiate = floorTiles[tileIdentity - 1];
                    GameObject instance      = Instantiate(toInstantiate, new Vector3(_row, _col, 0f), Quaternion.identity) as GameObject;
                    instance.transform.SetParent(boardHolder);
                }

                if (nodeContent != 0)
                {
                    GameObject toInstantiate = nodeTiles[nodeContent - 1];
                    GameObject instance      = Instantiate(toInstantiate, new Vector3(_row, _col, 0f), Quaternion.identity) as GameObject;
                    if (nodeContent == 38)
                    {
                        Debug.Log("spawning questions");
                        questionTrigger qt = instance.GetComponent <questionTrigger>();
                        qt.questionID   = questionCounter;
                        questionCounter = questionCounter + 1;
                    }
                    else if (nodeContent == 78)
                    {
                        Debug.Log("spawning info");
                        infoTrigger it = instance.GetComponent <infoTrigger>();
                        it.infoID   = infoCounter;
                        infoCounter = infoCounter + 1;
                    }
                    else
                    {
                    }
                    instance.transform.SetParent(boardHolder);
                }
                // events
                if (tileContent == 1)
                {
                    if (!playerSpawned)
                    {
                        Debug.Log(_row);
                        Debug.Log(_col);
                        playPos = new Vector3(_row, _col, 0f);
                        player.transform.position = playPos;
                    }
                    ;
                }
                ;
                // enemies
                if (tileContent == 6)
                {
                    GameObject toInstantiate = enemyTiles[0];
                    GameObject instance      = Instantiate(toInstantiate, new Vector3(_row, _col, 0f), Quaternion.identity) as GameObject;
                    instance.transform.SetParent(boardHolder);
                }
                ;

                if (tileContent != 0)
                {
                    Debug.Log(tileContent);
                    Debug.Log(_row);
                    Debug.Log(_col);
                }
                ;
                _row = _row + 1;
            }
            _row = 0;
            _col = _col + 1;
        }
    }