- Home /
How to modify scale of sprite
I have a problem with scaling my sprites. I wanted to make Ilusion of rotating around my sprites using scale and proper "back" of my sprite. I made a script, but for some reason gameobjects rotate so fast, that it looks more like switching sprites than slow "rotation" of my sprite.
public float speed = 0.1f;
public Sprite[] back;
private bool stop = false;
// Update is called once per frame
void FixedUpdate()
{
Debug.Log(speed);
if(transform.localScale.x <= -1f && !stop)
{
transform.localScale = new Vector2(-speed * Time.deltaTime/100,transform.localScale.y);
}
else
{
stop = true;
transform.localScale = new Vector2(-1f, transform.localScale.y);
}
Good day.
Are you sure that division is beeing executed?
Try this:
transform.localScale = new Vector2((-speed/100f) * Time.deltaTime,transform.localScale.y);
Answer by AbubakrKhan · Feb 04, 2019 at 09:32 AM
u can scale sprites through the engine buy creating a UI image and then applying that sprite on source image field in image script component of the script. Highlighted below in the picture.
you just have to apply a constant rotation on the image object you just created. by
void Update(){
transform.Rotate(Vector3.forward * speedRotate * Time.deltaTime);
}
or u can use rotateArround function if that is what you are looking for.
void Update() {
transform.RotateAround(Vector3.zero, Vector3.up, 20 * Time.deltaTime);
}
I wanted to avoid using rotations and quaternions, because I don't fully understands them, but after few modifications of my code it worked, but still too fast in my opinion and trying to put diferent numbers to modify rotation didn't seem to change anything. Can you tell me how those quaternions, are calculated?
Edit. also when I put transform.rotation = new Quaternion(transform.rotation.x, -1f,transform.rotation.z,transform.rotation.w);
to "fix" position it puts my rotation.y on position -161,571 ins$$anonymous$$d of -180.
Your answer
Follow this Question
Related Questions
Scaling GameObjects by Screen Resolution 0 Answers
How do I size a UI Image to fit the sprite exactly? 2 Answers
Stretch sprite one direction 1 Answer
Scale Objects become flat. 1 Answer
Bake mesh scale. 1 Answer