zoukankan      html  css  js  c++  java
  • Unity3D写雷电游戏(三)

    现在开始真正的游戏元素的编写了。

    第一步,让飞机动起来。

    首先是飞机的前进,通常2D中的做就是背景的循环滚动。

    在3D中我们可以让摄像机移动,背景我们可以做超一个大地形。。在地形上摆一些固定的东西。

        // Update is called once per frame
    void Update () {

    TurnLeft = false;
    TurnRight = false;

    if (Input.GetKey(KeyCode.W))
    {
    Vector3 screenPos = Camera.mainCamera.WorldToScreenPoint(this.transform.position);
    //print(screenPos.y);
    if (Screen.height > screenPos.y)
    this.transform.Translate(Vector3.forward * Time.deltaTime * m_nMoveSpeed);
    }
    if (Input.GetKey(KeyCode.S))
    {
    Vector3 screenPos = Camera.mainCamera.WorldToScreenPoint(this.transform.position);
    if (0 < screenPos.y)
    this.transform.Translate(Vector3.forward * Time.deltaTime * -m_nMoveSpeed);
    }

    if (Input.GetKey(KeyCode.A))
    {
    Vector3 screenPos = Camera.mainCamera.WorldToScreenPoint(this.transform.position);
    if (0 < screenPos.x)
    this.transform.Translate(Vector3.left * Time.deltaTime * m_nMoveSpeed);
    //向左转
    if (CurRotation < RotateLimit)
    {
    print(CurRotation);
    CurRotation += RotateSpeed;
    }
    TurnLeft = true;
    }


    if (Input.GetKey(KeyCode.D))
    {
    Vector3 screenPos = Camera.mainCamera.WorldToScreenPoint(this.transform.position);
    if (Screen.width > screenPos.x)
    this.transform.Translate(Vector3.left * Time.deltaTime * -m_nMoveSpeed);
    //向右转
    if (CurRotation > -RotateLimit)
    CurRotation -= RotateSpeed;
    TurnRight = true;
    }

    //回归
    if (!TurnLeft && !TurnRight)
    {
    if (CurRotation > 0.0)
    CurRotation -=RotateSpeed;
    else if (CurRotation < 0)
    CurRotation +=RotateSpeed;
    }




    Quaternion rot = Quaternion.AngleAxis(CurRotation, new Vector3(0, 0, 1));
    m_Plane.rotation = rot;

    //让相机和飞机一起以一定的速度前移
    this.transform.Translate(Vector3.forward * Time.deltaTime * m_nMoveSpeed);
    Camera.mainCamera.transform.Translate(Vector3.up * Time.deltaTime * m_nMoveSpeed);

    }

    飞机的主要控制代码。。不知为什么,我的两个角度限制没有效果。。郁闷。。有空还看一下。。



  • 相关阅读:
    oracle重新学习,主要是命令实用,有借鉴其他人博客
    cdn缓存立刻刷新
    python3发送需要双向认证的wss请求
    【2021.08.03】平等交流
    【2021.07.31】正面回应才是面对挑战的最好方式
    【2021.07.28】向晚
    【2021.07.25】过个生日
    【2021.07.17】Asoul——那些无法杀死我的,终会使我变得更加强大
    phaser3微信小游戏2
    eve-ng 配置apache2的虚拟目录
  • 原文地址:https://www.cnblogs.com/gameprogram/p/2285414.html
Copyright © 2011-2022 走看看