视频学习来源

移动和旋转

using UnityEngine;
using System.Collections;
/*
* Adminer:sun2955
* http:www.yinghy.com
* */
public class Move : MonoBehaviour {
private float moveSpeed = ;
private float rotateSpeed = ; // 使用进行初始化
void Start () { } //每一帧都会调用该函数
void Update () { // float inputx = Input.GetAxis("Horizontal"); //获得水平移动
// float inputy = Input.GetAxis("Vertical"); //获得垂直移动 //// this.transform.Translate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime); // if(Input.GetKey(KeyCode.A)){
// this.transform.Rotate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
// }
// if (Input.GetKey(KeyCode.D))
// {
// this.transform.Rotate(new Vector3(inputx * speed, 0, inputy * speed) * Time.deltaTime);
// }
if(Input.GetKey(KeyCode.W)){
this.transform.Translate(new Vector3(, , )* moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.S))
{
this.transform.Translate(new Vector3(, , ) * -moveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.A))
{
this.transform.Rotate(new Vector3(, , ) * -rotateSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.D))
{
this.transform.Rotate(new Vector3(, , ) * rotateSpeed * Time.deltaTime);
} }
//物理运动
void FixedUpdate()
{ }
}

相机的跟随移动

基本思路:主相机设定为一个比较好的视角,然后让相机以该视角的相对距离一直跟谁着移动。

实现思路:设定好相机的左边后,建立一个空物体,将相机挂在空物体的下面,空物体的左边是跟谁主角色进行变化,这样就能实现主角动,相机动,并且相机以一定的相对距离拍摄主角

using UnityEngine;
using System.Collections; public class CameraMove : MonoBehaviour {
private Transform tanktransform;
// Use this for initialization
void Start () {
tanktransform = GameObject.FindGameObjectWithTag("Player").transform;
} // Update is called once per frame
void LateUpdate () {
this.transform.position = tanktransform.position;
}
}

最新文章

  1. 11月3日上午PHP练习《投票》
  2. CSS背景background详解,background-position详解
  3. C++中public,protected,private派生类继承问题和访问权限问题
  4. hdu 2709 Sumsets
  5. 开发问题记录——ArcEngine问题记录
  6. js实现滑动解锁功能(PC+Moblie)
  7. Cassandra - Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
  8. Android 实现自己定义多级树控件和全选与反选的效果
  9. android的EditText获取另一个焦点
  10. 使用docker搭建kafka环境
  11. eclipse控制台中文乱码解决
  12. 数据分析基础之Linalg的使用
  13. C#:MVC引用Log4Net生成错误日志
  14. ASP.Net Core的Code Fist代码先行操作方法
  15. C#枚举(Enum)小结
  16. 小白6步搞定vue脚手架创建项目
  17. 利用Anaconda完美解决Python 2与python 3的共存问题
  18. 000 在什么位置写js代码
  19. 使用sys用户创建其他用户下的dblink
  20. PHP设计模式系列 - 数据访问对象模式

热门文章

  1. [NOIP2000]方格取数
  2. VS2013 单元测试(使用VS2013自带的单元测试)
  3. LCD驱动(FrameBuffer)实例开发讲解
  4. CentOS设置在同一窗口打开文件夹
  5. groupinfo
  6. The Basics
  7. [二]poi实践一
  8. Emmet:一个Html/Css快速编辑神器的插件
  9. Yii2 TimestampBehavior行为
  10. XML模式:Dublin Core