예제 #1
0
        // DEBUG - Spawn border (as trap) to see how creatures react on different colors
        private void SpawnTraps()
        {
            GameObject trapParent = new GameObject("traps");

            _parents.Add(trapParent);
            for (int i = 0; i < TrapAmount; i++)
            {
                BorderBehaviour trap = Instantiate(Resources.Load("Prefabs/border") as GameObject).GetComponent <BorderBehaviour>();

                Vector2 screenBounds = new Vector2(Width, Height);
                trap.transform.position = Camera.main.ScreenToWorldPoint(new Vector2(Random.Range(0f, screenBounds.x), Random.Range(0f, screenBounds.y)));

                trap.GetComponent <SpriteRenderer>().color = Color.red; // Make it red

                trap.transform.SetParent(trapParent.transform, true);
            }
        }
예제 #2
0
        private void SpawnBorders()
        {
            GameObject bordersParent = new GameObject("borders");

            _parents.Add(bordersParent);
            const float borderOffset = 5f / 2f;

            for (float x = 0; x <= Width; x += borderOffset)
            {
                for (float y = 0; y <= Height; y += borderOffset)
                {
                    if (x > 0 && x < Width - borderOffset && y > 0 && y < Height - borderOffset)
                    {
                        continue;
                    }

                    BorderBehaviour border = Instantiate(Resources.Load("Prefabs/border") as GameObject).GetComponent <BorderBehaviour>();
                    border.transform.position = Camera.main.ScreenToWorldPoint(new Vector2(x, y));

                    border.transform.SetParent(bordersParent.transform, true);
                }
            }
        }