I have a texture , the type is Sprite (2D and UI) , sprite mode : Single , it is a 9-sliced-Sprite , but when i draw the texture , it seem like it was acting like a normal texture , not a 9-sliced-Sprite , the size of the edges of the texture is still increasing. I am trying to make a Drag Selection Box. This is my code :
Vector3 beforeVector;
public void OnGUI()
{
if (isDragging && !Paused)
{
Texture te = (Texture)Resources.Load(Paths.UIRectPath + "/SelectedRect");
GUI.DrawTexture(new Rect(beforeVector.x, Screen.height - beforeVector.y, Input.mousePosition.x - beforeVector.x, beforeVector.y - Input.mousePosition.y) , te);
// . . .
}
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
isDragging = true;
beforeVector = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
{
isDragging = false;
beforeVector = new Vector3();
}
}
How can i draw a sliced sprite (or texture) without creating a UI image in the canvas ? I tried using this method . but the image position and size is weird. This is one using UI image :
Rect tt = new Rect(beforeVector.x, Screen.height - beforeVector.y, Input.mousePosition.x - beforeVector.x, beforeVector.y - Input.mousePosition.y);
SelectionRect.GetComponent<RectTransform>().sizeDelta = tt.size;
SelectionRect.GetComponent<RectTransform>().localPosition = tt.position;