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);

    }

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



  • 相关阅读:
    Spring RestTemplate 之put、delete请求
    Too many connections解决方案
    各个平台的mysql重启命令
    MySQL出现too many connections(1040)错误解决方法
    EXCEL中,如何引用一个单元格中的数据,作为另一个单元格内容中的一部分?
    [翻译][Java]ExecutorService的正确关闭方法
    MySQL:日期函数、时间函数总结(MySQL 5.X)
    MySQL 获得当前日期时间 函数
    线程本地变量ThreadLocal
    split 分割 字符串(分隔符如:* ^ : | , . ?) 及注意点
  • 原文地址:https://www.cnblogs.com/gameprogram/p/2285414.html
Copyright © 2011-2022 走看看