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 /
This question was closed Aug 31, 2015 at 09:08 PM by Ashky for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Ashky · Jun 14, 2014 at 09:02 AM · c#2dspritesize

How can I set the position and size of a sprite from inside a script ?

Hello, Unity Community.

I am currently developing a 2D game, and I want to know if it's possible to set a sprite's position and size from inside a script(C#). I looked at the Sprite.Create entry in the scripting API, but it lacks an example and it only helped confuse me.

It would help me design levels much easier by doing math rather than designing levels by eye in the editor.

Comment
Add comment · Show 1
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 PouletFrit · Jun 14, 2014 at 02:02 PM 0
Share

You change the position and size of sprite just like you change the position and size of any gameObject in Unity. Change the transform's position and scale values. So yes you can access these in scripts.

Unity Scripting API: Transform

1 Reply

  • Sort: 
avatar image
5

Answer by robusto · Jun 14, 2014 at 02:05 PM

It is possible.

 public float width = 1;
 public float height = 1;
 public Vector3 position = new Vector3( 10, 5, 0 );
 
 void Awake()
 {
    // set the scaling
    Vector3 scale = new Vector3( width, height, 1f );
    transform.localScale = scale;
    // set the position
    transform.position = position;
 }

http://docs.unity3d.com/ScriptReference/Transform.html

Comment
Add comment · Show 1 · Share
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 Ashky · Jun 14, 2014 at 05:26 PM 0
Share

This solved my design issues. Thank you very much.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Implementing 2D Sprite Collisions 1 Answer

2 problems when workin with sprites on Unity3D 1 Answer

Recoloring animated sprites [Solved] 2 Answers

Size limits on sprite sheet? 1 Answer

Rotate the weapon sprite with a joystick 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