コード例 #1
0
    void OnMouseDown()
    {
        grid.ShowAllTiles();

        if (_eventUID != uidEvents.EVENT_DRAGGING)
        {
            _eventUID = uidEvents.EVENT_DRAGGING;
        }
    }
コード例 #2
0
    void OnMouseUp()
    {
        grid.HideAllTiles();

        if (_eventUID == uidEvents.EVENT_ONTILE)
        {
            _eventUID = uidEvents.EVENT_SPAWN;
        }
        else
        {
            _eventUID = uidEvents.EVENT_IDLE;
        }
    }
コード例 #3
0
    void CheckEvents()
    {
        if (_eventUID == uidEvents.EVENT_IDLE)
        {
            transform.position = _startLocation;
            transform.rotation = _startRotation;
        }
        else if (_eventUID == uidEvents.EVENT_DRAGGING)
        {
            Ray     ray      = Camera.main.ScreenPointToRay(Input.mousePosition);
            Vector3 rayPoint = new Vector3(ray.GetPoint(_distance).x, transform.position.y, ray.GetPoint(_distance).z);

            _distance = Vector3.Distance(transform.position, Camera.main.transform.position);

            transform.position = rayPoint;
            transform.rotation = _startRotation;
        }
        else if (_eventUID == uidEvents.EVENT_SPAWN)
        {
            SpawnTower();
            _eventUID = uidEvents.EVENT_IDLE;
        }

        if (_eventUID == uidEvents.EVENT_DRAGGING || _eventUID == uidEvents.EVENT_ONTILE)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            Debug.DrawRay(ray.origin, ray.direction * 100, Color.yellow);

            if (Physics.Raycast(ray, out hit))
            {
                if (hit.transform.name == "Tile" && this.transform.position != hit.transform.position)
                {
                    _currentTile = hit.transform;
                    _eventUID    = uidEvents.EVENT_ONTILE;
                    CheckOnTile();
                }
                else
                {
                    _eventUID = uidEvents.EVENT_DRAGGING;
                }
            }
        }
    }