当前位置:   article > 正文

Unity 2D游戏制作_unity2d随机生成预制体

unity2d随机生成预制体

调试背景

2D游戏的制作最重要的是层的设置

先设置两个层①Layers②Edit Layers③Sorting Layers添加两个层BackGround和Front

调试大雁

创建2D object改名BackGround设置背景图片修改为BackGround 0层

创建2D object添加大雁图片Ctrl+6,保存,把大雁动态模型全选,插入。调整时间可以看起来舒服,调整所在层为BackGround 1层

添加脚本使大雁从屏幕右边开始飞入左边飞出

publicclassSwanFly : MonoBehaviour {

    //天鹅起飞的位置

    privateVector3 startPosition;

    publicfloat speed;

         // Use this for initialization

         void Start () {

        Debug.Log("屏幕的宽度" + Screen.width);

        Debug.Log("屏幕的高度" + Screen.height);

        Vector3 screenSize = Camera.main.ScreenToWorldPoint(newVector3(Screen.width, Screen.height, 0));

        float swanExtentsX = transform.GetComponent<Renderer>().bounds.extents.x;

        startPosition = newVector3(screenSize.x + transform.position.y, transform.position.z);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/958908?site
推荐阅读
相关标签
  

闽ICP备14008679号