Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by darkmwar · Jul 09, 2014 at 11:44 PM · cameraguitexturecolliderscale

Texture Size doesn't match collider size

Hi, I am running in to the issue where I want a given texture, (in this case solid color), to match up to the size of the collider. Both of these things are in the same game object.

I tried to use code to match the size of texture to the exact size of collider so it is visible in the game of where the collider is. My attempt was this:

 void Start ()
         {        
                 collider_a = gameObject.GetComponent<BoxCollider2D> ();
                 
                 collider_a.size = ....;
                 collider_a.center = ....;
         }
 
 void FixedUpdate ()
         {
                 //constantly changing the sizes of the collider
                 collider_a.size = new Vector2 (colliderSize, 2); //colliderSize is already declared in the class
             
         }
 
 private void OnGUI(){
         GUI.DrawTexture (new Rect (x, y, colliderSize, 2), a, ScaleMode.StretchToFill); //texture a is already declared
     }

This is a very stripped down version of my code. variables are all declared and working.

The issue is, i need to find a way to make the texture as big as the collider. This makes the texture much smaller than the actual collider size, even though the parameters are identical. collider of size (5,2) would need a texture of size (~90,~100) to have the same size.

I have x,y currently set to 0 for debugging, but x,y is also messed up if i try to relate it to the collider center - size. Can anyone give me some insights into what im doing wrong?

Update: The texture is just a whole picture of one color. It is drawn by the script GUI function. I did it this way so that I can change it's size as the collider zones changes. This texture is already created, but it's size is monitored by the rectangle variables at the second last line of code. new rect (.....).

The script and the collider is in the same EMPTY game object. fixed update allows me to control the colliders sizes

Comment
Add comment · Show 8
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image darkmwar · Jul 10, 2014 at 07:57 PM 0
Share

hints? anyone?

avatar image awest · Jul 12, 2014 at 02:29 PM 0
Share

I'm a total beginner at GUI, but I believe the Rect constructor uses pixel units where as colliders use Unity units.

You might resolve that issue by using a textured plane and scale that ins$$anonymous$$d.

avatar image darkmwar · Jul 14, 2014 at 07:16 AM 0
Share

can you expand a little bit on textured plane and scale? so i should draw gui in textured planes?

avatar image robertbu · Jul 14, 2014 at 08:15 AM 0
Share

It is unclear where the issue is here. First you need to define what kind of object you are using to display the texture. Second, you need to explain how you are dealing with the texture. Is it a sprite created at edit time, or are you creating a new sprite at runtime?

avatar image darkmwar · Jul 17, 2014 at 06:39 PM 0
Share

@robertu I have added additional details

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trying to make a Diablo like minimap, but I am having problems. Bug? 0 Answers

How to maintain high resolution custom background images for GUI elements on different screen sizes? 0 Answers

Path Trigger Animation 1 Answer

Help with cameras and enabling/disabling GUItextures? 1 Answer

I have a GUI element that highlights an onscreen object with a circle. This circle needs to scale according to the object's distance from the camera in order to compensate for perspective, but the thickness of the circle needs to stay the same. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges