u3d新手 零碎知识点记录

*** 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");
      }
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值