Example #1
0
    //builder vars

    void Update()
    {
        //Remember: Update runs on EVERYONE's computer, wether or not they own this
        //particular player object.
        if (isLocalPlayer == false)
        {
            return;
        }

        //Spawns Unit DEBUG ONLY
        if (Input.GetKeyDown(KeyCode.Space))
        {
            UnitSys.spawnUnit(0, new Vector3(17f, -1f, 25f), Quaternion.identity);
        }
        if (Input.GetKeyDown(KeyCode.M))
        {
            UnitSys.spawnUnit(3, new Vector3(17f, -1f, 25f), Quaternion.identity);
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            BuildSys.ToggleBuildMode();
        }
        if (BuildSys.buildMode)
        {
            BuildSys.BuildingControl();
        }
        else
        //Move selected units to point
        if (Input.GetMouseButtonDown(1))
        {
            //Slow script
            if (selectedUnits.Count <= 0)
            {
                return;
            }
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            //There should be at least 1 selected unit.

            if (Physics.Raycast(ray, out hit, 10000))
            {
                Interactable interactable = hit.collider.GetComponent <Interactable> ();
                //.Log("JORI JORI AJA AJA " + hit.collider.name);
                if (interactable != null)
                {
                    if (myUnits.Count > 0)
                    {
                        foreach (GameObject unit in selectedUnits)
                        {
                            //TO BE REMOVED IF FOUNF SOLUTION ON NOT DELETEiNG OBJECTS
                            if (unit == null)
                            {
                                selectedUnits.Remove(unit);
                                continue;
                            }


                            unit.GetComponent <Unit> ().SetFocus(interactable);
                        }
                    }
                    return;
                }
            }


            if (Physics.Raycast(ray, out hit, 10000, movementMask))
            {
                moveUnits(hit.point);
            }
        }
    }