撰写了文章 发布于 2017-04-04 23:00:20
[UNITY] 2D Game Development Walkthrough
有一个构思中的2D Puzzle-Platformer,想要在4月20号前做出一个demo。
作为我的第一个unity游戏,可能会很简单,但是也要占用我大部分时间,所以《the art of game design》估计得放放了。
先就这个视频看看在制作2D Platformer游戏时候的基本模式。
This video will discuss the background and foreground construction, characters, effects,camera tracking, animation and scripting.
1:26 可以往2D项目里面添加3D Object(Enter the Gungeon的橘子233)
2:45 利用线性插值完成背景的视差效果:
// Lerp the background's position between itself and it's target position.
backgrounds[i].position = Vector3.Lerp(backgrounds[i].position, backgroundTargetPos, smoothing * Time.deltaTime);
4:05 使用Animation (Ctrl+6)编辑Sprite动画,类似3DsMax的Curve Editor。
8:07 角色转身时使用函数flip()来翻转角色:
// If the input is moving the player right and the player is facing left...
if(h > 0 && !facingRight)
// ... flip the player.
Flip();
// Otherwise if the input is moving the player left and the player is facing right...
else if(h < 0 && facingRight)
// ... flip the player.
Flip();void Flip ()
{
// Switch the way the player is labelled as facing.
facingRight = !facingRight;
// Multiply the player's x local scale by -1.
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
8:48 在Update()下检查角色是否在地面上(grounded),使用Physics2D.Linecast()来检查:
// The player is grounded if a linecast to the groundcheck position hits anything on the ground layer.
grounded = Physics2D.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
其中“1 << LayerMask.NameToLayer("Ground")”卡了我好久。。。然后看到了这个
http://answers.unity3d.com/questions/701862/2d-example-project-parameter-of-physics2dlinecast.html
完美地解答了我的问题。
顺便,这个问题 How do I use layermasks? 也十分值得一看:
http://answers.unity3d.com/questions/8715/how-do-i-use-layermasks.html
2017年4月4日23:00:10