开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 1914|回复: 3
收起左侧

[C#源码] 飞机游戏之控制飞机飞行

[复制链接]

结帖率:33% (1/3)
发表于 2013-2-18 14:09:07 | 显示全部楼层 |阅读模式   上海市上海市
本帖最后由 永久禁言 于 2013-2-18 14:23 编辑
  1. using UnityEngine;
  2. using System.Collections;

  3. public class FPSFlight : MonoBehaviour
  4. {

  5.         public float moveSpeed = 3.0f;
  6.         public float rotationSpeedX = 1;
  7.         public float rotationSpeedY = 1;
  8.         public float maxSpeed = 10.0f;
  9.         public Transform shipModel;
  10.         public float actualSpeed = 0.0f;
  11.         //因为要用场景中的camera来做位置限制
  12.         public Camera camera;

  13.         private Vector3 moveDirection = Vector3.zero;
  14.         private float baseRotationX = 0.0f;
  15.         private float baseRotationY = 0.0f;
  16.         private float oldSpeed = 0.0f;
  17.        
  18.         private float recToX = 0f;
  19.         void Start()
  20.         {
  21.                
  22.         }
  23.        
  24.         void FixedUpdate ()
  25.         {
  26.                 //控制机身旋转;
  27.                 baseRotationX = Input.GetAxis("Horizontal")*rotationSpeedX;
  28.                 baseRotationY = -Input.GetAxis("Vertical")*rotationSpeedY;
  29.                 float angleZ = baseRotationX * 30;
  30.                 float angleX = baseRotationY * 15;
  31.                 shipModel.localEulerAngles = new Vector3 (angleX, 0, angleZ);
  32.                
  33.                 float toX = -Input.GetAxis("Horizontal") * moveSpeed;
  34.                 float toZ = -Input.GetAxis("Vertical") * moveSpeed;
  35.                
  36.                 //限制;
  37.                 Vector3 screenPos = camera.WorldToScreenPoint(shipModel.position);
  38.                 if(Input.GetAxis("Horizontal")<0){
  39.                         //向左移动;
  40.                         if(screenPos.x<=50){
  41.                                 toX = 0;
  42.                         }
  43.                 }
  44.                
  45.                 if(Input.GetAxis("Horizontal")>0){
  46.                         //向右移动;
  47.                         if(screenPos.x>=Screen.width-50){
  48.                                 toX = 0;
  49.                         }
  50.                 }
  51.                
  52.                 if(Input.GetAxis("Vertical")<0){
  53.                         //向下移动;
  54.                         if(screenPos.y<=0){
  55.                                 toZ = 0;
  56.                         }
  57.                 }
  58.                
  59.                 if(Input.GetAxis("Vertical")>0){
  60.                         //向上移动;
  61.                         if(screenPos.y>=Screen.height-110){
  62.                                 toZ = 0;
  63.                         }
  64.                 }
  65.                
  66.                 //移动机身;
  67.                 moveDirection.Set(toX,0, toZ);
  68.                 this.transform.position += moveDirection * Time.deltaTime;
  69.         }
  70.        
  71. }
复制代码
结帖率:100% (17/17)

签到天数: 9 天

发表于 2013-2-18 14:27:28 | 显示全部楼层   河北省石家庄市
俺不懂,顶下
回复 支持 反对

使用道具 举报

结帖率:33% (1/3)
 楼主| 发表于 2013-2-18 14:23:04 | 显示全部楼层   上海市上海市
小磊 发表于 2013-2-18 14:11
换行都没,坑爹了

我编辑下。。。。。。。。。
回复 支持 反对

使用道具 举报

结帖率:60% (3/5)

签到天数: 3 天

发表于 2013-2-18 14:11:47 | 显示全部楼层   上海市上海市
换行都没,坑爹了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表