Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (!freeze)
        {
            if (!isEditFurniture)
            {
                //положение мыши из экранных в мировые координаты
                Vector3 mousePosition = cell.transform.position;
                var     angle         = Vector2.Angle(Vector2.right,
                                                      mousePosition - transform.position); //угол между вектором от объекта к мыше и осью х
                transform.eulerAngles =
                    new Vector3(0f, 0f,
                                transform.position.y < mousePosition.y ? angle : -angle);                 //немного магии на последок

                Move(_rigidbody2D, speed, false);
            }
            else
            {
                Debug.Log(posFurniture);
                transform.localPosition = posFurniture;
                Move(_rigidbody2DFurniture, strong, true);
            }

            if (Input.GetKeyDown(KeyCode.Q))
            {
                if (!isEditFurniture)
                {
                    gameObjectFurniture = actionPlayer.GetSelectedFurniture();
                    if (gameObjectFurniture != null)
                    {
                        _rigidbody2DFurniture  = gameObjectFurniture.GetComponent <Rigidbody2D>();
                        isEditFurniture        = true;
                        transform.parent       = gameObjectFurniture.transform;
                        posFurniture           = transform.localPosition;
                        _rigidbody2D.simulated = false;

                        var angle = Vector2.Angle(Vector2.right,
                                                  gameObjectFurniture.transform.position - transform.position);
                        transform.eulerAngles = new Vector3(0f, 0f,
                                                            transform.position.y < gameObjectFurniture.transform.position.y ? angle : -angle);
                    }
                }
                else
                {
                    isEditFurniture        = false;
                    transform.parent       = null;
                    _rigidbody2D.simulated = true;
                    gameObjectFurniture    = null;
                    _rigidbody2DFurniture  = null;
                    //astarPath.Scan();
                }
            }
        }
    }