u3d新手 零碎知识点记录
2016-02-17 10:26
225 查看
*** U3D使用哪个IDE?
默认mono,使用VS 2013比较好。
如何设置脚本编辑工具:
Edit-- >Preferences-->External Tools面板有一个External Script Editor 选择脚本编辑软件
*** 如何设置vs的快捷键和eclipse一样?
一个一个设置,没有批量导入功能。不爽。
*** 给一个物体一个力
1) 物体加上 rigidBody ,
2)
Rigidbody rd;
rd = GetComponent<Rigidbody>();
float x = Input.GetAxis ("Horizontal"
);
float z = Input.GetAxis ("Vertical");
Vector3 pos = new Vector3 (x,0.0f,z);
rd.AddForce (pos * speed);
*** 碰撞
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("pick up")){
Debug.Log("碰撞了");
other.gameObject.SetActive(false);
}
}
*** 相机跟随
1)
Vector3 offset;
offset = transform.position - player.transform.position;
transform.position = player.transform.position + offset;
2) 在 smooth s内跟随移动
public Transform target;
public float smoothing =5f;
Vector3 offset;
offset = transform.position - target.position;
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp(transform.position,targetCamPos,smoothing * Time.deltaTime);
*** Update、Fixedupdate、LateUpdate 区别
Update 每一帧都调用
FixedUpdate 固定更新 处理刚体 物理逻辑时用
lateUpdate 晚于更新 相机跟随用
*** 花1s时间 物体从 pos 移动得到 target
var start : Transform;
var end : Transform;
function Update () {
transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}
*** 脚本绘制一个纹理
oneTexture = (Texture2D)Resources.Load("OneTexture/Grass");
GUI.DrawTexture(new Rect(110, 20, 120, 120), oneTexture, ScaleMode.ScaleToFit, true, 0);
*** 声音播放
public AudioClip fire;
audio.PlayOneShot(fire);
*** 移动物体
playerRigidbody.MovePosition(transform.position + movement);
*** 旋转向鼠标点击的方向
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if(Physics.Raycast(camRay,out floorHit,camRayLength,floorMask)){
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
*** 加载正运行的场景 scene
Application.LoadLevel (Application.loadedLevel);
*** 敌人攻击脚本
void OnTriggerEnter (Collider other)
{
if(other.gameObject == player)
{
playerInRange = true;
}
}
void OnTriggerExit (Collider other)
{
if(other.gameObject == player)
{
playerInRange = false;
}
}
timer += Time.deltaTime;
if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0)
{
Attack ();
}
if(playerHealth.currentHealth <= 0)
{
anim.SetTrigger ("PlayerDead");
}
默认mono,使用VS 2013比较好。
如何设置脚本编辑工具:
Edit-- >Preferences-->External Tools面板有一个External Script Editor 选择脚本编辑软件
*** 如何设置vs的快捷键和eclipse一样?
一个一个设置,没有批量导入功能。不爽。
*** 给一个物体一个力
1) 物体加上 rigidBody ,
2)
Rigidbody rd;
rd = GetComponent<Rigidbody>();
float x = Input.GetAxis ("Horizontal"
);
float z = Input.GetAxis ("Vertical");
Vector3 pos = new Vector3 (x,0.0f,z);
rd.AddForce (pos * speed);
*** 碰撞
void OnTriggerEnter(Collider other) {
if(other.gameObject.CompareTag("pick up")){
Debug.Log("碰撞了");
other.gameObject.SetActive(false);
}
}
*** 相机跟随
1)
Vector3 offset;
offset = transform.position - player.transform.position;
transform.position = player.transform.position + offset;
2) 在 smooth s内跟随移动
public Transform target;
public float smoothing =5f;
Vector3 offset;
offset = transform.position - target.position;
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp(transform.position,targetCamPos,smoothing * Time.deltaTime);
*** Update、Fixedupdate、LateUpdate 区别
Update 每一帧都调用
FixedUpdate 固定更新 处理刚体 物理逻辑时用
lateUpdate 晚于更新 相机跟随用
*** 花1s时间 物体从 pos 移动得到 target
var start : Transform;
var end : Transform;
function Update () {
transform.position = Vector3.Lerp(start.position, end.position, Time.time);
}
*** 脚本绘制一个纹理
oneTexture = (Texture2D)Resources.Load("OneTexture/Grass");
GUI.DrawTexture(new Rect(110, 20, 120, 120), oneTexture, ScaleMode.ScaleToFit, true, 0);
*** 声音播放
public AudioClip fire;
audio.PlayOneShot(fire);
*** 移动物体
playerRigidbody.MovePosition(transform.position + movement);
*** 旋转向鼠标点击的方向
Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit floorHit;
if(Physics.Raycast(camRay,out floorHit,camRayLength,floorMask)){
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
playerRigidbody.MoveRotation(newRotation);
}
*** 加载正运行的场景 scene
Application.LoadLevel (Application.loadedLevel);
*** 敌人攻击脚本
void OnTriggerEnter (Collider other)
{
if(other.gameObject == player)
{
playerInRange = true;
}
}
void OnTriggerExit (Collider other)
{
if(other.gameObject == player)
{
playerInRange = false;
}
}
timer += Time.deltaTime;
if(timer >= timeBetweenAttacks && playerInRange && enemyHealth.currentHealth > 0)
{
Attack ();
}
if(playerHealth.currentHealth <= 0)
{
anim.SetTrigger ("PlayerDead");
}
相关文章推荐
- ANDROID_MARS学习笔记_S01原始版_020_Mp3player001_歌曲列表
- 关于CocoaPod升级的一些事
- 解决:Permission denied: make_sock: could not bind to address
- apache之httpd启动、终止、重启小结
- linux CentOS 6.5 中安装与配置JDK-7
- CentOS6.5使用yum命令方便快捷安装Nginx
- nginx内置变量
- CSS“隐藏”元素的多种方法的对比
- 编译安装Nginx
- Xshell下的文件传输(从windows到Linux)
- android 快捷键
- maven 子项目如何使用父项目的jar包
- MVC4.0 扩展辅助方法
- IOS开发证书变成“此证书的签发者无效”解决方法
- 【线性代数】图与网络
- 使用 Docker 建立 Mysql 集群
- linux yum使用管理详细使用
- poj 3280 Cheapest Palindrome(区间dp)
- linux下提示bash:command not found
- iOS -OPenGL的屏幕截图