Get sprite size and position
I need some help to find a way to get the sprite's size.
I try to put a texture on my sprite like this :
GUI.DrawTexture(new Rect(mySpriteBotLeftX, mySpriteBotLeftY, mySpriteWidth, mySpriteHeight), myTexture);
In my script I use a RequireComponent to get a SpriteRenderer. In scene mode I would like to be able to change the size of this sprite to easily get a rect of the size that I need. I tried something like this but it didn't work :
sprite_size = GetComponent().sprite.rect.size; local_sprite_size = sprite_size / GetComponent<SpriteRenderer>().sprite.pixelsPerUnit; world_size = local_sprite_size; world_size.x *= transform.lossyScale.x; world_size.y *= transform.lossyScale.y; screen_size = 0.5f * world_size / Camera.main.orthographicSize; screen_size.y *= Camera.main.aspect; screen_size.x *= Camera.main.aspect; in_pixels = new Vector3(screen_size.x * Camera.main.pixelWidth, screen_size.y * Camera.main.pixelHeight, 0) * 0.5f;
Any ideas to help me with this ?
Your answer
Follow this Question
Related Questions
Problem Changing Sprites with an Array of Sprites 1 Answer
assigning sprites to game object via script 0 Answers
Getting name of Spritesheet on runtime with C#? (Not individual SpriteName) 1 Answer
How to change a button image with script? 1 Answer
How do i make a character selection menu (2d game) ? 2 Answers