Exemplo n.º 1
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                GameObject hitObject = hit.transform.gameObject;
                selectedUnits.add(hitObject);
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                if (hit.transform.gameObject.GetComponent <HealthComponent>())
                {
                    //Attack Logic
                    foreach (GameObject unit in selectedUnits.selectedUnits)
                    {
                        unit.GetComponent <AttackComponent>().acquireTarget(hit.transform.gameObject);
                    }
                }
                else
                {
                    foreach (GameObject unit in selectedUnits.selectedUnits)
                    {
                        unit.GetComponent <NavigationComponent>().setDestination(hit.point);
                        unit.GetComponent <AttackComponent>().target = null;
                    }
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                spiderFactory.createSpider(hit.point);
            }
        }
    }
Exemplo n.º 2
0
 public override void Execute(Vector3 mousePos, SelectedUnits selectedUnits)
 {
     try
     {
         GameObject  unitToSelect = new Raycast().Cast(mousePos, Vector2.zero);
         BasicSpider spider       = (unitToSelect.GetComponent(typeof(BasicSpider)) as BasicSpider);
         if (selectedUnits.contains(spider))
         {
             selectedUnits.remove(spider);
             spider.selected = false;
         }
         else
         {
             selectedUnits.add(spider);
             spider.selected = true;
         }
     }
     catch (NullReferenceException e)
     {
         selectedUnits.deselectAll();
         return;
     }
 }