Hello Guest

Author Topic: Scaling Sprite Not working  (Read 3880 times)

mblazek

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Scaling Sprite Not working
« on: March 10, 2014, 07:11:44 pm »
I am making a health bar.

So i have two tk2dSprite's  In code I want to adjust the scale of the tk2dSprite that is the fill.   I think I am doing everything correctly but it does nothing to the sprite at all:

Code: [Select]
public float scaleToSet = .5f;
tk2dSprite myBar;

// Use this for initialization
void Awake () {
Debug.Log (myBar);
myBar = (tk2dSprite)transform.GetComponent<tk2dSprite> ();
myBar.scale.Set (scaleToSet, 1.0f, 1.0f);
}


void Update () {


}

public void scaleX() {
myBar.scale.Set (scaleToSet, 1.0f, 1.0f);
Debug.Log ("WE SHOULD SCALE: " + scaleToSet);
}


I will be calling scaleX from another script.. but for testing on awake i tell it to scale to .5 and it does not do anything.   

Please help.

mblazek

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Scaling Sprite Not working
« Reply #1 on: March 10, 2014, 07:23:33 pm »
Its actually flashing now.  So if looks like it scales then jumps back up to full. 

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Scaling Sprite Not working
« Reply #2 on: March 11, 2014, 01:37:20 pm »
.scale is a property of a value type (Vector3). You can't call .Set on it as it will be setting it to a temporary variable that is discarded.
You should always do myBar.scale = new Vector3(...)