Beispiel #1
0
 void Update()
 {
     if (_disabled)
     {
         return;
     }
     if (Input.GetKeyDown(KeyCode.F2))
     {
         EndPlacement();
     }
     if (_currentlyActiveObject != null)
     {
         if (Input.GetAxisRaw("Rotate") != 0)
         {
             _currentlyActiveObject.transform.Rotate(Vector3.up, RotationSpeed * Time.unscaledDeltaTime * Input.GetAxisRaw("Rotate"));
         }
         if (updateRaycastHit())
         {
             _currentlyActiveObject.gameObject.SetActive(true);
             _currentlyActiveObject.transform.position = _lastHit.point;
             if (_currentlyDragging)
             {
                 if (!Input.GetMouseButton(0))
                 {
                     _currentlyDragging = false;
                     _currentlyActiveObject.SetInPlacedState();
                     _currentlyActiveObject = null;
                 }
             }
             else
             {
                 if (Input.GetMouseButtonDown(0))
                 {
                     var placedObject = Instantiate(_currentlyActiveObject);
                     placedObject.SetInPlacedState();
                     _placedObjects.Add(placedObject);
                     EndPlacement();
                     OnObjectPlaced();
                 }
             }
         }
         else
         {
             _currentlyActiveObject.gameObject.SetActive(false);
         }
     }
     else
     {
         if (Input.GetMouseButtonDown(0) && updateRaycastHit())
         {
             var placedObject = _lastHit.collider.GetComponentInParent <PlacementObject>();
             if (placedObject != null)
             {
                 _currentlyActiveObject = placedObject;
                 _currentlyActiveObject.SetInPlacementState();
                 _currentlyDragging = true;
             }
         }
     }
 }
Beispiel #2
0
    public void StartPlacement(GameObject prefab)
    {
        if (_currentlyActiveObject != null)
        {
            Destroy(_currentlyActiveObject.gameObject);
        }
        var newObject = Instantiate(prefab);

        _currentlyActiveObject = newObject.AddComponent <PlacementObject>();
        _currentlyActiveObject.CreatedFromPrefab = prefab;
        _currentlyActiveObject.SetInPlacementState();
    }