Hey, sorry for the video quality. I'm using quicktime to capture my screen and i'm not sure how to get the best results yet. I'll look into that eventually.
Today, i've made the background sprites (trees and grass) scroll. All thoses objects are contained in a game object named "Background". I've attached a dedicated script to this game object. This script apply a constant translation to the left to make the background move. I've made it loop, so it's never ending.
Then i ran into a common issue : how may i structure my code properly? I have 3 game objects : Taco, SmallWall, Background. When Taco hit a SmallWall, the Background has to stop scrolling. But as, i've attached scripts to each objects, i have no "main loop" which knows all the object in the scene and so can't communicate with all of them to synchronize them.
Rather than setting up a "main loop", i used TAGS and MESSAGES... which allows me to stays more object oriented =)
In Unity, you may define and set "tags" to objects. I set the tag of my background as "Background". This allows me to find it from the SmallWall script, using the function FindGameObjectsWithTag("Background"). Then i sent a message to my Background object: SendMessage("Scroll", false). It actually execute a function ("Scroll") and pass it some parameters ("false").
it worked really well :)
No comments:
Post a Comment