The stage can broadcast a message telling each of the sprites to fall.Ĭreate a different message for each sprite. The sprite should show up, fall, stamp itself, go to a random spot at the top of the screen and hide again.Ĭopy the code to each of the other sprites. Place the hide block at the end of the falling code to hide the sprite when it returns to the top. When it returns to the top of the screen however, you can still see it. Place the show block above the repeat block. Now that it hides when the green flag is clicked, it needs to show itself before it falls so that the user can see it fall. The sprites seem to just appear at the bottom. Now, click on the code that makes the sprites fall. Test the code by clicking the green flag. To make all the sprites perform the same actions, copy the code by dragging it to each of the sprites. To keep this from happening, use the when green flag is clicked and hide blocks to make the sprites disappear when the green flag is clicked. That's because the other sprites are also black and the sprites stops falling when it touches black. The sprite doesn't fall if it hits another sprite. So this example uses random -240 to 240 for the X and 180 for the Y. The stage spans -240 to 240 from left to right and -180 to 180 from top to bottom. To do this, try using the random variable inside a go to block. To make the game more fun, make the starting location of the sprite unpredictable. The sprite will fall until it hits the ground, then it will leave a stamp of itself and return to the top of the screen. The block also needs to return to the top of the screen so it can fall and stamp itself again.ĭrag the sprite back to its starting position and then place the go to XY block under the stamp block. This example plays the sound pop when the sprite lands. Have the sprite make a sound as it lands. Place the stamp block, under the repeat until block. The sprite should fall until it hits the ground.Īfter the sprite falls, it should stamp itself. Place the touching color black condition inside the repeat until block. The sprite should stop moving down when it touches the black. Place the repeat until block around the change Y by block. To make something keep happening until a condition is true, use the repeat until block. The sprite should keep falling until it touches the color black. Now you have a condition that reads, touching color block. Then, click on the color box and on the black bar at the bottom of the stage. Make the sprite keep moving down until it touches the ground or another stamp.Įach of the backgrounds has a black bar at the bottom and each of the stamps are black on top.įrom the sensing menu, drag out a touching color condition. Start by making the sprite move down using the change Y by block.Ĭlick on it to make sure the sprite moves down. Now, it's triggering on start of the game.In this video, you will learn how to make the sprites fall. So, I put the gravity on code inside the OnTrigger. For some reason the trigger will not call the other function. UPDATE The trigger is firing, now that I have replaced the IEnumerable with void and removed the wait. I just can't figure out how to set it up properly. Public class FallingCube : MonoBehaviour Using UnityEngine using System.Collections I have a cube set up with a box collider and a rigidbody (nothing checked) and a childed empty game object with a box collider set to "is trigger" and a script as follows. I want to set up a block that, after the player has touched, it will drop in 3 seconds. I just started with unity not too long ago.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |