unity3d 摄像机跟随鼠标和键盘的控制

鼠标控制:

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);
}



}



}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388189.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《必然》九、享受重混盛宴,是每个人的机会

今天说的是《必然》的第七个关键词&#xff0c;过滤Filtering。1我们需要过滤如今有一个问题&#xff0c;弥漫在我们的生活当中&#xff0c;困扰着所有人。那就是“今天我要吃什么呢&#xff1f;”同样的&#xff0c;书店里这么多的书&#xff0c;我要看哪一本呢&#xff1f;网…

IDEA 插件开发入门教程

2019独角兽企业重金招聘Python工程师标准>>> IntelliJ IDEA 是目前最好用的 JAVA 开发 IDE&#xff0c;它本身的功能已经非常强大了&#xff0c;但是每个人的需求不一样&#xff0c;有些需求 IDEA 本身无法满足&#xff0c;于是我们就需要自己开发插件来解决。工欲善…

安卓代码还是xml绘制页面_我们应该绘制实际还是预测,预测还是实际还是无关紧要?

安卓代码还是xml绘制页面Plotting the actual and predicted data is frequently used for visualizing and analyzing how the actual data correlate with those predicted by the model. Ideally, this should correspond to a slope of 1 and an intercept of 0. However, …

Mecanim动画系统

本期教程和大家分享Mecanim动画系统的重定向特性&#xff0c;Mecanim动画系统是Unity3D推出的全新的动画系统&#xff0c;具有重定向、可融合等诸多新特性&#xff0c;通过和美工人员的紧密合作&#xff0c;可以帮助程序设计人员快速地设计出角色动画。一起跟着人气博主秦元培学…

【嵌入式硬件Esp32】Ubuntu 1804下ESP32交叉编译环境搭建

一、ESP32概述EPS32是乐鑫最新推出的集成2.4GWi-Fi和蓝牙双模的单芯片方案&#xff0c;采用台积电(TSMC)超低功耗的40nm工艺&#xff0c;拥有最佳的功耗性能、射频性能、稳定性、通用性和可靠性&#xff0c;适用于多种应用和不同的功耗要求。 ESP32搭载低功耗的Xtensa LX6 32bi…

你认为已经过时的C语言,是如何影响500万程序员的?...

看招聘职位要c语言的占比真不多了&#xff0c;是否c语言真得落伍了&#xff1f; 看一下许多招聘平台有关于找纯粹的c语言开发的占比确实没有很多&#xff0c;都被Java&#xff0c;php&#xff0c;python等等語言刷屏。这对于入门正在学习c语言的小白真他妈就是惊天霹雳&#xf…

换热站起停条件

循环泵 自动条件&#xff1a; 一、循环泵启动条件 两台泵/三台泵&#xff1a; 1&#xff09;本循环泵在远程状态 2&#xff09;本循环泵自动状态 3&#xff09;本循环泵没有故障 4&#xff09;二次网的回水压力&#xff08;测量值&#xff09;>设定值 5&#xff09;…

云尚制片管理系统_电影制片厂的未来

云尚制片管理系统Data visualization is a key step of any data science project. During the process of exploratory data analysis, visualizing data allows us to locate outliers and identify distribution, helping us to control for possible biases in our data ea…

JAVA单向链表实现

JAVA单向链表实现 单向链表 链表和数组一样是一种最常用的线性数据结构&#xff0c;两者各有优缺点。数组我们知道是在内存上的一块连续的空间构成&#xff0c;所以其元素访问可以通过下标进行&#xff0c;随机访问速度很快&#xff0c;但数组也有其缺点&#xff0c;由于数组的…

软件公司管理基本原则

商业人格&#xff1a;独立履行责任 独立坚持原则两大要素&#xff1a;1)靠原则做事&#xff0c;原则高于一切。2)靠结果做交换&#xff0c;我要什么我清楚两个标准&#xff1a; 1)我不是孩子&#xff0c;我不需要照顾2)承认逻辑&#xff0c;我履行我的责任社会人心态: 1)用社会…

201771010102 常惠琢《面向对象程序设计(java)》第八周学习总结

1、实验目的与要求 (1) 掌握接口定义方法&#xff1b; (2) 掌握实现接口类的定义要求&#xff1b; (3) 掌握实现了接口类的使用要求&#xff1b; (4) 掌握程序回调设计模式&#xff1b; (5) 掌握Comparator接口用法&#xff1b; (6) 掌握对象浅层拷贝与深层拷贝方法&#xff1b…

新版 Android 已支持 FIDO2 标准,免密登录应用或网站

谷歌刚刚宣布了与 FIDO 联盟达成的最新合作&#xff0c;为 Android 用户带来了无需密码、即可登录网站或应用的便捷选项。 这项服务基于 FIDO2 标准实现&#xff0c;任何运行 Android 7.0 及后续版本的设备&#xff0c;都可以在升级最新版 Google Play 服务后&#xff0c;通过指…

t-sne原理解释_T-SNE解释-数学与直觉

t-sne原理解释The method of t-distributed Stochastic Neighbor Embedding (t-SNE) is a method for dimensionality reduction, used mainly for visualization of data in 2D and 3D maps. This method can find non-linear connections in the data and therefore it is hi…

oracle操作

imp kfqrlcs/kfqrlcshx fileC:\kfqrlcs.dmp fully //创建临时表空间 create temporary tablespace kfqrlcs_temp tempfile C:\oracledata\kfqrlcs_temp.dbf size 32m autoextend on next 32m maxsize 8048m extent management local; //tempfile参数必须有 //创建数据表…

strust2自定义拦截器

1.创建一个拦截器类&#xff0c;继承MethodFilterInterceptor类&#xff0c;实现doIntercept方法 package com.yqg.bos.web.interceptor;import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor; import com.y…

Android Studio如何减小APK体积

最近在用AndroidStudio开发一个小计算器&#xff0c;代码加起来还不到200行。但是遇到一个问题&#xff0c;导出的APK文件大小竟然达到了1034K。这不科学&#xff0c;于是就自己动手精简APK。下面我们大家一起学习怎么缩小一个APK的大小&#xff0c;以hello world为例。 新建工…

js合并同类数组里面的对象_通过同类群组保留估算客户生命周期价值

js合并同类数组里面的对象This is Part I of the two-part series dedicated to estimating customer lifetime value. In this post, I will describe how to estimate LTV, on a conceptual level, in order to explain what we’re going to be doing in Part II with the P…

C#解析HTML

第一种方法&#xff1a;用正则表达式来分析 [csharp] view plaincopy 转自网上的一个实例&#xff1a;所有的href都抽取出来&#xff1a; using System; using System.Net; using System.Text; using System.Text.RegularExpressions; namespace HttpGet { c…

帮助开发人员学习

在浏览器中使用真实环境学习新技术 https://www.katacoda.com/ 转载于:https://www.cnblogs.com/zuxing/p/9829143.html

【转】SASS用法指南

SASS用法指南 阮一峰的&#xff0c;偏sass用法教程sass入门 偏实战的基础用法