自制第一人称:

1、新建一个球、一个摄像机,把球和摄像机放在一个位置。

2、把下面代码托付给球。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move3 : MonoBehaviour
{
    public float sensitivityX = 5f;
    public float sensitivityY = 5f;

public float sensitivetyKeyBoard = 0.1f;
    public float sensitivetyMouseWheel = 10f;

private GameObject Playercamera;
    public Rigidbody rigidbody;
    public float speed = 5;

void Start()
    {
       // undefined
       Playercamera = GameObject.Find("PlayerCamera");
    }

void Update()
    {
      //  undefined
      //滚轮实现镜头缩进和拉远
  if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
           // undefined

Playercamera.GetComponent<Camera>().fieldOfView = Playercamera.GetComponent<Camera>().fieldOfView - Input.GetAxis("Mouse ScrollWheel") * sensitivetyMouseWheel;
        }
        //鼠标右键实现视角转动,类似第一人称视角  
        if (Input.GetMouseButton(0))
        {
           // undefined
      
float rotationX = Input.GetAxis("Mouse X") * sensitivityX;
            transform.Rotate(0, rotationX, 0);

float rotationY = Input.GetAxis("Mouse Y") * sensitivityY;
            Playercamera.transform.Rotate(-rotationY, 0, 0);
        }

}
    void FixedUpdate()
    {
       // undefined
      //控制移动
  float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

//朝一个方向移动 new Vector3(h, 0, v) * speed * Time.deltaTime是个向量
        transform.Translate(new Vector3(h, 0, v) * speed * Time.deltaTime);
        //移动到一个位置
        //rigidbody.MovePosition(transform.position + new Vector3(h, 0, v) * speed * Time.deltaTime);
    }
}

unity3d 常用代码相关推荐

  1. Unity3D常用代码总结

    1 GUI汇总 function OnGUI() { GUI.Label(Rect(1,1,100,20),"I'm a Label"); //1 GUI.Box(Rect(1,2 ...

  2. Unity 使用教程 之 Unity3D常用的知识点归纳

    Unity 使用教程 之 Unity3D常用的知识点归纳 注意:数据结构和算法很重要!图形学也很重要!大的游戏公司很看重个人基础,综合能力小公司看你实际工作能力,看你的Demo. 1.什么是渲染管道? ...

  3. Unity3D常用设计模式之工厂模式

    Unity3D常用设计模式<工厂模式>   工厂模式(Factory Pattern)是游戏开发中比较常用的设计模式.这种类型的设计模式属于创建型模式,它提供了一种创建对象实例的最佳方式. ...

  4. pytorch常用代码

    20211228 https://mp.weixin.qq.com/s/4breleAhCh6_9tvMK3WDaw 常用代码段 本文代码基于 PyTorch 1.x 版本,需要用到以下包: impo ...

  5. 一、PyTorch Cookbook(常用代码合集)

    PyTorch Cookbook(常用代码合集) 原文链接:https://mp.weixin.qq.com/s/7at6y2NcYaxGGN8syxlccA 谢谢作者的付出.

  6. GitHub上7000+ Star的Python常用代码合集

    作者 | 二胖并不胖 来源 | 大数据前沿(ID:bigdataqianyan) 今天二胖给大家介绍一个由一个国外小哥用好几年时间维护的Python代码合集.简单来说就是,这个程序员小哥在几年前开始保 ...

  7. 收藏!PyTorch常用代码段合集

    ↑↑↑关注后"星标"Datawhale 每日干货 & 每月组队学习,不错过 Datawhale干货 作者:Jack Stark,来源:极市平台 来源丨https://zhu ...

  8. PyTorch常用代码段合集

    ↑ 点击蓝字 关注视学算法 作者丨Jack Stark@知乎 来源丨https://zhuanlan.zhihu.com/p/104019160 极市导读 本文是PyTorch常用代码段合集,涵盖基本 ...

  9. JavaScript常用代码

    在这存一下JavaScript常用代码: 1.封装输出 1 var log = function() { 2 console.log.apply(console, arguments) 3 } 4 5 ...

  10. javascript常用代码大全

    http://caibaojian.com/288.html     原文链接 jquery选中radio//如果之前有选中的,则把选中radio取消掉 $("#tj_cat .pro_ca ...

最新文章

  1. .net core实践系列之短信服务-Api的SDK的实现与测试
  2. 扫描线三巨头 hdu1928hdu 1255 hdu 1542 [POJ 1151]
  3. nio的优势_BIO、NIO、AIO 介绍和适用场景分析
  4. 不得不说的wepapi 优化
  5. Pandas 排序之后索引问题
  6. 网页连接数据库 服务器,关于asp网页连接远程服务器上数据库问题
  7. java write阻塞_java socket/output stream writes:他们阻塞?
  8. 使用Python写的第一个网络爬虫程序
  9. delay() 方法
  10. java 线程池不抛异常 异常捕获失败问题
  11. excel 个人日常记账——统计报表
  12. 零门槛修改微信步数(基于虚拟xposed)
  13. 鸿蒙系统 微内核 sel4,引入成熟的微内核技术改良reactos,如sel4
  14. android tv香橙派镜像,香橙派-如何通过dd制作系统镜像
  15. 按头安利 好看又实用的相机 单反免抠元素素材看这里
  16. 2022年团体程序设计天梯赛记录(部分题解)
  17. UIAlertController Extention
  18. subplots_adjust()函数--matplotlib
  19. php 获取数组四分位,如何在JavaScript(或PHP)中获得数组的中位数和四分位数/百分位数?...
  20. 成都聚星共创:拼多多砍单有什么技巧

热门文章

  1. 手机弹奏计算机音乐的软件,APP推荐:11款简单好用工具的APP,一定要懂!
  2. 使用自己的服务器中转远程桌面
  3. 凭证反过账 金蝶k3_金蝶软件k3凭证反过账
  4. 啦啦外卖41.7亲测可用!插件齐全!含顾客APP,商家APP ,骑手APP!需要的拿去研究
  5. 淘淘商城第1讲——你给介绍介绍,什么叫淘淘商城?
  6. 计算机课题名称怎么取,课题名称:微型计算机操作入门
  7. 计算机键盘正确指法,计算机盲打键盘指法图顺口溜
  8. 34 模板方法模式(模板方法设计模式)详解
  9. 怎样用一个鼠标和键盘控制两台电脑
  10. IntelliJ IDEA For Mac 的破解方法