Ejemplo n.º 1
0
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, npcMask))
        {
            if (Input.GetMouseButtonDown(0))
            {
                Debug.Log("Selected " + hitInfo.collider.name);
                peasant     = GameObject.Find(hitInfo.collider.name).GetComponent <Peasant>();
                npcSelected = !npcSelected;
                UIEventHandler.BuildingSelect(hitInfo.transform);
            }
        }
        if (actionActive)
        {
            offsetMousePos = new Vector3(Input.mousePosition.x + 45f, Input.mousePosition.y - 45f, Input.mousePosition.z);
            imageToShow.transform.position = offsetMousePos;
            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, environmentMask))
            {
                if (Input.GetMouseButtonDown(0) && npcSelected)
                {
                    Debug.Log("Going for " + hitInfo.collider.name);
                    npcSelected = !npcSelected;
                    target      = hitInfo.collider.name;
                    material    = hitInfo.collider.transform;
                    SetRoutine();
                    imageToShow.gameObject.SetActive(false);
                    actionActive = false;
                }
            }
            if (Input.GetMouseButtonDown(1))
            {
                imageToShow.gameObject.SetActive(false);
                actionActive = false;
                UIEventHandler.BuildingDeselect();
            }
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (Input.GetMouseButtonDown(0) && !blockChosen)
        {
            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
            {
                if (hitInfo.collider.tag != "Ground" && hitInfo.collider.tag != "NPC")
                {
                    UIEventHandler.BuildingSelect(hitInfo.collider.transform);
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            UIEventHandler.BuildingDeselect();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            toPlace = cube;
            placementSize.SetSize(cube.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            toPlace = sphere;
            placementSize.SetSize(sphere.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            toPlace = cylinder;
            placementSize.SetSize(cylinder.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            toPlace = peasant;
            placementSize.SetSize(new Vector3(1, 1, 1));
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        else if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            toPlace = road;
            placementSize.SetSize(road.transform.localScale);
            ToggleBlockChosen();
            TogglePlaceObjectSize();
        }
        if (Input.GetMouseButtonDown(0) && blockChosen)
        {
            PlaceUnit(toPlace);
        }
    }