Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        // Have the object follow the mouse
        if (placeable != null)
        {
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mousePosition   = tileGrid.GetCellCenterWorld(tileGrid.WorldToCell(mousePosition));
            mousePosition.z = 0;
            if (!cachePosition.Equals(mousePosition))
            {
                cachePosition = mousePosition;
                placeable.transform.position = mousePosition;
            }
        }

        // Code to detach the object once you click the mouse
        if (Input.GetMouseButtonDown(0) && placeable != null)
        {
            if (place.isCheck)
            {
                //检测是否有资源

                bool r = Messenger.BroadcastReturn <Dictionary <string, int>, bool>(EventCode.RESOURCE_CHECK, placeable.GetComponent <BuildControl>().cost);
                StartBuild(r);


                //Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                //mousePosition.z = 0;
                //mousePosition = tileGrid.GetCellCenterWorld(tileGrid.WorldToCell(mousePosition));
                //  commandManager.SpawnPlacebable(prefabToPlace, mousePosition);
            }
        }
        else if (Input.GetMouseButtonDown(1))
        {
            Destroy(placeable);
            placeable     = null;
            prefabToPlace = null;
        }
    }