Search Unity

Problems about prefabs and velocity affected by scripts

Discussion in 'Scripting' started by ysleungrockman, Apr 2, 2014.

  1. ysleungrockman

    ysleungrockman

    Joined:
    Mar 16, 2014
    Posts:
    32
    I am making a game which is similar to breakout but replacing blocks with different enemies. And now there are some problems. One of the problem is I combined the health bar, enemy and the scripts as one prefab. When I copy another one to the same scene, when I play it, only one of the health bar is deducted and another is not affected. How can I do to make them work separately? Another problem is that as it is 2D game. I use Physics 2D for the ball. But when the ball hits the walls or enemies, it will change direction horizontally or vertically but not like in 2D momentum. So to prevent this, I add script to make that when velocity of x or y direction becomes zero, the velocity will change. I set it will only after the ball is hit by the paddle because I want the ball will fall vertically at first. But when I play it, it does change velocity without touching the paddles. So how to fix these two problems? (I attached the a zip file in the bottom link for the whole project. The project is not much tidy. The scenes are in assets file, prefabs are in prefabs file and scripts are in fyp2 file.)

    https://www.dropbox.com/s/iqvjnx0sboepdzs/PinChicken.7z