鼠标控制:

using UnityEngine;
using System.Collections;

public class shubiao : MonoBehaviour {
//public Transform firepos;
public int Ball=30;
public int CurBall=1;
public Rigidbody projectile;
public Vector3 point;
public float time=100f;
public GameObject Juese;
public GameObject lumian;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
Juese=GameObject.Find ("shijue");
GameObject PengZhuang1=GameObject.Find ("PengZhuang1");
GameObject PengZhuang2=GameObject.Find ("PengZhuang2");
GameObject PengZhuang3=GameObject.Find ("PengZhuang3");
GameObject PengZhuang4=GameObject.Find ("PengZhuang4");
GameObject PengZhuang5=GameObject.Find ("PengZhuang5");
   GameObject PengZhuang6=GameObject.Find ("PengZhuang6");
if(Juese==null)
{

return;
}
if(Input.GetMouseButton(0))
{
Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast (ray,out hit))
{
if(hit.transform==Juese.transform)
{
print("命中了球");

}
if(hit.transform==PengZhuang1.transform)
{
print("碰撞了墙1");
return;
}
if(hit.transform==PengZhuang2.transform)
{
print("碰撞了墙2");
return;
}
if(hit.transform==PengZhuang3.transform)
{
print("碰撞了墙3");
return;
}
if(hit.transform==PengZhuang4.transform)
{
print("碰撞了墙4");
return;
}
if(hit.transform==PengZhuang5.transform)
{
print("碰撞了墙5");
return;
}
if(hit.transform==PengZhuang6.transform)
{
print("碰撞了墙6");
Application.LoadLevel(1);
return;
}
point=hit.point;
Juese.transform.LookAt(new Vector3(point.x,Juese.transform.position.y,point.z));
time=Time.realtimeSinceStartup;
Move(0.15f);

}
}
}
void Move(float speed)
{
if(Mathf.Abs (Vector3.Distance(point,transform.position))>=1.3f)
{

// Rigidbody clone2;
// clone2 = Instantiate(projectile, point, firepos.rotation) as Rigidbody;
// clone2.velocity = transform.TransformDirection(Vector3.forward * 10);
//transform.Translate(point);
Juese.transform.Translate(Vector3.forward* Time.deltaTime*20);
// transform.Translate (point* Time.deltaTime*20);
// print(point.x);
// print("forward"+Vector3.forward.x);
// CharacterController cctl= GetComponent<CharacterController>();
// Vector3 v=Vector3.ClampMagnitude(point,speed);
// cctl.Move(v);
}

}
void OnMouseDown()
{
Debug.Log("OnMouseDown");

}

}

键盘控制:

using UnityEngine;
using System.Collections;

public class shijue : MonoBehaviour {
//public GameObject ballgo;
// Use this for initialization
void Start () {

}
// Update is called once per frame
void Update () {

// ballgo=GameObject.Find ("zidan");
// if(Ball==null||firepos==null)
// return;
if (Input.GetButtonDown("Fire1")) {
//if (Input.GetKeyDown(KeyCode.Space))
//{
// Rigidbody clone1;
// clone1 = Instantiate(projectile, firepos.position, firepos.rotation) as Rigidbody;
// clone1.velocity = transform.TransformDirection(Vector3.forward * 120);
//}
if(Input.GetKey (KeyCode.W))
{
print("----------w"); 
transform.Translate (Vector3.forward * Time.deltaTime*60);
}
if(Input.GetKey (KeyCode.S))
{

print("---------------s");
transform.Translate (Vector3.forward * Time.deltaTime*-60);
}
if(Input.GetKey (KeyCode.A))
{
print("---a");
transform.Rotate(Vector3.up * Time.deltaTime*-60);
}
if(Input.GetKey (KeyCode.D))
{

print("------------d");
transform.Rotate(Vector3.up * Time.deltaTime*60);
}

}

}

unity3d 摄像机跟随鼠标和键盘的控制相关推荐

  1. Unity3D摄像机跟随物体移动的代码控制

    摄像机跟随物体方法一是把摄像机设置为物体Player的子物体,给Player添加移动脚步就可以摄像机跟随Player移动.移动的简单脚步 using UnityEngine; using System ...

  2. unity3d 摄像机跟随角色时被物体遮挡解决方案

    unity3d 摄像机跟随角色时被物体遮挡解决方案 未被遮挡时 为了解决这个问题,在这里我们需要用到 Physics.RaycastAll:使用方法详见圣典 首先 ,我们引入命名空间 System.C ...

  3. 关于UNITY3d摄像机跟随人物转动的脚本

    首先,我也是一名初学者,最近刚刚开始下手实战,今天分享一下关于人物视角跟随摄像机视角转动的脚本. 以下为简单的摄像机跟随脚本: using UnityEngine; using System.Coll ...

  4. Unity3D摄像机跟随人物

    本篇文章和大家介绍的是摄像机跟随人物,这里的视角主要是从人物的背后跟随的. 首先新建一个C#脚本,命名为MyFollow,然后把以下代码粘贴进去,保存: AخA 1 using UnityEngine ...

  5. unity3D摄像机跟随

    为摄像机添加一个脚本. 先定义一个跟随的目标,以及一个三维向量. 在初始时刻,先让该三维向量等于摄像机初始位置与目标(角色)位置的差向量. 接下来定义一个根据物理帧刷新频率的函数,让摄像机位置向量每一 ...

  6. unity鼠标控制镜头旋转_Unity Camera教程之 摄像机跟随鼠标移动而旋转

    FollowMouseMove 脚本具体内容如下: using UnityEngine; public class FollowMouseMove : MonoBehaviour { public f ...

  7. unity摄像机跟随鼠标旋转

    第一种 float vertical = Input.GetAxis("Mouse X") float horizontal = Input.GetAxis("Mouse ...

  8. [实践] 创建具有鼠标和键盘同样控制效果的Flash按钮

    由于Flash中可以使用png透明格式的图片,所以可以做一些特殊效果, 比如浮雕.阴影等等这些用jpg和gif格式是不容易实现的!由于项目的需要, 要做一个浮雕按钮,同时可以用键盘和鼠标控制,并且有响 ...

  9. unity3d 摄像机跟随角色时 画面抽搐问题

    //摄像机update频率更新情况下 position rotation 结果 不插值 插值 摄像机高速移动抽搐 插值 插值 角色跑步抽搐 不插值 不插值 摄像机高速移动抽搐 插值 不插值 角色跑步抽 ...

最新文章

  1. 打通新场景,源创计划第一弹!“悟道”大模型应用合作交流会
  2. plsql programming 10 日期和时间戳
  3. WKWebview 的使用及坑
  4. css3整理--border-radius
  5. 十二、深入Python列表和元组
  6. thumbnailator压缩图片并存至Excel单元格代码
  7. 牛客多校第二场 G transform
  8. Python机器学习:KNN算法之01KKN基础
  9. 【辨异】—— 可见 vs. 不可见
  10. machine learning之PCA、ICA
  11. 简单说一下阿里云到底是干什么的?
  12. 易捷行云EasyStack携手北联国芯,共筑鲲鹏生态
  13. 内网环境部署zabbix5.0版本监控(一)
  14. 大一python基础编程试卷_python--大一期末测试题(含答案)
  15. java经典50道编程题(很好练逻辑思维的题)(第一篇)
  16. 3D打印鞋或将成为新时尚 Nike也加入
  17. hlsl函数 ddx ddy
  18. zookeeper关闭默认管理端口admin.serverPort=8080
  19. ZigBee设备OTA过程研究及优化
  20. uniapp微信小程序项目启动步骤

热门文章

  1. linux在指定目录多个文件中搜索关键字
  2. leetcode 93. 复原IP地址 思考分析
  3. 【智能车Code review】——坡道图像与控制处理
  4. Anaconda中下载速度贼慢?
  5. XADD和NEG命令
  6. python云计算开发技术_云计算开发学习笔记:Python3 面向对象技术简介
  7. uva 1623——Enter The Dragon
  8. 142. 环形链表 II golang
  9. Qt编译错误:无法解析的外部符号 __imp__CloseServiceHandle __imp__OpenSCManager
  10. POJ 1741tree-点分治入门