public void Init(Formations.formation _formation, FormationSpawner _spawner)
    {
        formation = _formation;
        spawner   = _spawner;
        if (!spawner)
        {
            Debug.Log("We need a spawner to do this");
        }
        if (formation == null)
        {
            Debug.Log("formation is empty");
        }


        GameObject prefab = spawner.GetPrefab(formation.icon);

        unitModel = Instantiate(prefab, transform.position, transform.rotation) as GameObject;
        unitModel.GetComponent <CapsuleCollider>().enabled = false;
        unitModel.name = prefab.name;
        unitModel.transform.SetParent(transform);
        unitModel.transform.Rotate(0.0f, (Random.value * 50.0f) - 25.0f, 0.0f);
        unitModel.transform.localScale = Vector3.one;
        UnitControl unitControl = unitModel.GetComponent <UnitControl>();

        unitControl.SetWaitingState(true);

        GameObject canvas = transform.Find("Canvas").gameObject;

        canvas.AddComponent <InputRepeater>().SetTarget(gameObject);
        nameText      = transform.Find("Canvas/Name").GetComponent <Text>();
        nameText.text = formation.name.ToUpper();
        costText      = transform.Find("Canvas/Cost").GetComponent <Text>();
        costText.text = formation.cost.ToString();
    }
Example #2
0
    void Start()
    {
        homePos = transform.localPosition;

        cameraControl = Camera.main.transform.root.GetComponent <CameraControl>();
        cameraControl.SetCameraMode(CameraControl.Mode.EditRedTeam);

        eventSystem = EventSystem.current;
        screenSize  = new Vector2(Screen.width, Screen.height);
        spawner     = GameObject.Find("Spawner").GetComponent <FormationSpawner>();

        Formations.formation[] allFormations = Formations.allFormations;
        markers = new List <Transform>();
        slots   = new List <Transform>();
        for (int i = 0; i < 18; i++)
        {
            Transform marker = transform.Find(string.Format("Slot{0}", i.ToString("D2")));
            markers.Add(marker);
            marker.GetComponent <Renderer>().enabled = false;
        }

        for (int i = 0; i < allFormations.Length; i++)
        {
            Transform  marker      = markers[Mathf.Clamp(i, 0, markers.Count - 1)];
            GameObject newUnitSlot = Instantiate(unitSlotPrefab, marker.position, marker.rotation) as GameObject;
            newUnitSlot.transform.SetParent(transform);
            newUnitSlot.transform.localScale = Vector3.one;
            slots.Add(newUnitSlot.transform);
            newUnitSlot.GetComponent <UnitSelectorSlot>().Init(allFormations[i], spawner);
        }

        int gridSize      = 4;
        int formationSize = 8;

        for (int x = 0; x < gridSize; x++)
        {
            for (int y = 0; y < 4; y++)
            {
                float      xPos   = (x * formationSize) - (formationSize * (gridSize - 1) / 2);
                float      yPos   = (y * formationSize) - (formationSize * (gridSize - 1) / 2);
                Vector3    newPos = spawnGridOrigin.position + new Vector3(xPos, 0.25f, yPos);
                Quaternion newRot = Quaternion.identity;
                if (team == Team.Blue)
                {
                    newRot = Quaternion.AngleAxis(180, Vector3.up);
                }

                GameObject    newFormationSlot = Instantiate(formationSlotPrefab, newPos, newRot) as GameObject;
                FormationSlot slotControl      = newFormationSlot.GetComponent <FormationSlot>();
                slotControl.SetUnitSelector(this);
            }
        }
        listScrollGoal = markers.Count / 4;

        SetScreenWidth();
    }
    // Use this for initialization
    void Start()
    {
        formationSpawner = GameObject.FindObjectOfType <FormationSpawner>();

        SpawnEnemies();

        moveRight = false;
        moveLeft  = false;
        moveUp    = false;
        moveDown  = false;

        distance = transform.position.z - Camera.main.transform.position.z;
        Vector3 leftMost  = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, distance));
        Vector3 rightMost = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, distance));
        Vector3 downMost  = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, distance));
        Vector3 upMost    = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, distance));

        xMin = leftMost.x + xMinPadding;
        xMax = rightMost.x - xMaxPadding;
        yMin = downMost.y + yMinPadding;
        yMax = upMost.y - yMaxPadding;
    }
Example #4
0
 void Start()
 {
     mat = GetComponent <Renderer>().material;
     formationSpawner = GameObject.Find("Spawner").GetComponent <FormationSpawner>();
 }