2017년 1월 5일 목요일

Unity - 4 - help move camera with object(player)

In some games, it's important factor that camera must usually follow player.
So!! we will make camera follow player in this time


1. The most easy way to make camera follow player is just inherit camera to player ! then camera will always follow player and it seems like that it solved all of problem


2. but in this case , you can see , it was not good idea ! because our played object is sphere ! yeah it is rolling and rolling!! so the camera inherited to player also roll !!

 3. so ! we need write script. let's add new script


4. Write this simple code (we already learned how can we open script editor)
then , you can see unfamiliar code
       public GameObject player
you're probably thinking "Oh it's a creating instance code ! but ... where is class which defined before declaration??? "
yeah you're right 'GameObject' class also member class in namespace !! and you will soon realize how this class is convenient
and you can also find transform.position and it return position value (3 - vector value) of each object
so offset is fixed value(or distance between this object and player) and it's set at 'start'
and used to repeatedly move camera position in fixed distance with player


5. But ! at first time , I wondered that how that script can recognize PLAYER object even though the script is CAMERA's script and you can see about script in the right bottom there is 'player' and blank next to 'player' if you click it , you can see select menu !
then , you can select what do you want to connect 'player' in script !!

6. Finally, if you test, you will know that this is what i wanted   

댓글 없음:

댓글 쓰기