Пример #1
0
    void Paint()
    {
        Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        Debug.DrawRay(mouseRay.origin, mouseRay.direction, Color.red, int.MaxValue);
        RaycastHit hit;

        if (Physics.Raycast(mouseRay, out hit, int.MaxValue, maskCanvas))
        {
            if (Brush != null)
            {
                PaintType  brushType       = Brush.GetComponent <PaintTile>().PaintTileType;
                GameObject objectToDestroy = GetGameObject(hit);
                Vector3    position        = GetPosition(hit);
                Vector2    PositionInArray = GetPositionInArray(objectToDestroy);

                GameObject Ink = Instantiate(Brush, position, Quaternion.identity, gameObject.transform);
                Ink.GetComponent <PaintTile>().PositionX     = (int)PositionInArray.x;
                Ink.GetComponent <PaintTile>().PositionY     = (int)PositionInArray.y;
                Ink.GetComponent <PaintTile>().PaintTileType = brushType;
                gameBuilder.AddElemntToPaint((int)PositionInArray.x, (int)PositionInArray.y, Ink);

                Destroy(hit.collider.gameObject);

                if (onPlayerPaint != null)
                {
                    onPlayerPaint();
                }
            }
        }
        if (Physics.Raycast(mouseRay, out hit, int.MaxValue, maskPicker))
        {
            Source = hit.collider.gameObject;

            Brush = Source.GetComponent <ObjectSource>().source;
            if (onPlayerPaint != null)
            {
                onPlayerPaint();
            }
        }
    }