Author Topic: How can i move sprites via script in other sprites ?  (Read 5293 times)

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
How can i move sprites via script in other sprites ?
« on: May 11, 2014, 11:20:09 AM »
If i try to move the sprite the script on it it works .
but if i try to instantiate sprites in certain order and then access them it wont move them .
The funny thing is : I can rename them, i can print their position ( Which prints the right position but in the viewport it is not moving at all )
And more : all these was in edit mode ( [ExecuteInEditMode] ) .
If i do the same in runtime it works, but i cant save it, if i try to copy the sprites when it runs, stop the game, past the sprites, their position return to 0.0.0 again... How can i fix that ?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: How can i move sprites via script in other sprites ?
« Reply #1 on: May 11, 2014, 12:58:49 PM »
That's the way Unity works. Changes done in playmode are never* saved. Question is, how are you instantiating them and how are you trying to rename them? Post some code, and we can see where it goes bad.



*Certain exceptions exist, since changing the raw assets will persist.

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: How can i move sprites via script in other sprites ?
« Reply #2 on: May 11, 2014, 01:02:21 PM »
I guess if the object with the "UIScroll view" on it and the "UIPanel" on it is marked on static could make this happen ? i got away with an other solution but i guess this would of fix it, am i right ?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: How can i move sprites via script in other sprites ?
« Reply #3 on: May 11, 2014, 01:52:47 PM »
Possibly. If it's marked Static, it means just that - it will not update the positon, rotation or scale. Removing static should fix that.

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: How can i move sprites via script in other sprites ?
« Reply #4 on: May 12, 2014, 01:10:26 AM »
Just rechecked it, it wont matter if the sprite is even in the root ( UIRoot ) . the moment you check ( Turn it on ) the " UILabel " component or the " UISprite " component it snaps to 0,0,0 .

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How can i move sprites via script in other sprites ?
« Reply #5 on: May 13, 2014, 07:56:04 AM »
NGUITools.AddChild instantiates everything at (0, 0, 0) relative to the parent. I don't know what you're using there. If simply turning on a sprite makes it snap, then I'd wonder what else you have there. Nothing on the sprite would change its position. Unless you have anchors enabled, perhaps.