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.pswp.cn/news/388189.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388189.shtml
英文地址,請注明出處:http://en.pswp.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入門 偏實戰的基礎用法