当前位置:网站首页>Unity学习笔记 之 发射小球碰撞物体的代码记录
Unity学习笔记 之 发射小球碰撞物体的代码记录
2022-07-20 11:53:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
绑定在摄像机上的脚本
using UnityEngine;
using System.Collections;
public class abc : MonoBehaviour {
//设置移动速度
public int speed = 5;
//设置将被初始化载入的对象
public Transform newobject = null;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//通过左右方向键,或A、D字母键控制水平方向。实现往左、往右移动
float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
//通过上下方向键,或W、S字母键控制垂直方向,实现往前、往后移动
float z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
//移动 绑定物的 x、z 轴,即移动 摄像机的 x、z 轴。
transform.Translate(x,0,z); //推断是否按下鼠标的左键 if (Input.GetButtonDown(“Fire1”)) { //实例化命令:Instantiate(要生成的物体, 生成的位置, 生成物体的旋转角度) Transform n = (Transform)Instantiate(newobject, transform.position, transform.rotation); //转换方向 Vector3 fwd = transform.TransformDirection(Vector3.forward); //给物体加入力度 //Unity5之前的写法:n.rigidbody.AddForce(fwd * 2800); n.GetComponent<Rigidbody>().AddForce(fwd * 2800); } //推断是否按下字母button Q if (Input.GetKey(KeyCode.Q)) { //改变 绑定物的 y 轴,即改变 摄像机的 y 轴。 transform.Rotate(0,-25*Time.deltaTime,0,Space.Self); } //推断是否按下字母button E if (Input.GetKey(KeyCode.E)) { transform.Rotate(0,25*Time.deltaTime,0,Space.Self); } //推断是否按下字母button Z if (Input.GetKey(KeyCode.Z)) { //旋转 绑定物的 y 轴,即旋转 摄像机的 y 轴。 transform.Rotate(-25*Time.deltaTime,0,0,Space.Self); } //推断是否按下字母button X if (Input.GetKey(KeyCode.X)) { //旋转 绑定物的 y 轴,即旋转 摄像机的 y 轴。 transform.Rotate(25*Time.deltaTime,0,0,Space.Self); } //推断是否按下字母button F if (Input.GetKey(KeyCode.F)) { //移动 绑定物的 y 轴。即移动 摄像机的 y 轴。 transform.Translate(0,-5*Time.deltaTime,0); } //推断是否按下字母button C if (Input.GetKey(KeyCode.C)) { //移动 绑定物的 y 轴,即移动 摄像机的 y 轴。
transform.Translate(0,5*Time.deltaTime,0); } } }
绑定在发射的小球上的脚本
using UnityEngine;
using System.Collections;
public class xiaomie : MonoBehaviour {
// Use this for initialization
void Start () {
//销毁物体,gameObject。目測应该是指物体自身。即达到自我销毁的需求.
Destroy(gameObject, 3.0f);
}
// Update is called once per frame
void Update () {
}
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/108407.html原文链接:https://javaforall.cn
边栏推荐
- KusionStack 开源|Kusion 模型库和工具链的探索实践
- 多线程与高并发(二)—— Synchronized 加锁解锁流程
- 2022/7/18-7/19
- R语言epiDisplay包的kap函数计算配对列联表的计算一致性的比例以及Kappa统计量的值(总一致性、期望一致性)、使用xtabs函数生成二维列联表、使用wttable参数设置权重表参数为w2
- mongodb安全集群搭建
- 自动推理的逻辑05--谓词演算
- OSPF综合实验
- Director of Shanghai Bureau of culture and Tourism: safety is the lifeline of culture and tourism, and we are seizing the new track of yuancosmos
- 技术解析|Doris Connector 结合 Flink CDC 实现 MySQL 分库分表 Exactly Once精准接入
- 高能同步辐射光源科学数据管理策略研究与应用
猜你喜欢
Hcip notes day 10
没有投机stock的命,该放弃的就明智果断放弃才是上策
Thymeleaf uploads files in web pages
lambda
Flinksql reads Kafka data and reports an error
Peripherals: I2C communication details
玩转Makefile文件
Tiflash source code reading (V) deltatree storage engine design and implementation analysis - Part 2
Dynamic memory management (malloc, free, calloc, realloc, flexible array)
上海文旅局局长:安全是文旅业的生命线,正抢抓元宇宙新赛道
随机推荐
调研280+篇文献!CVPR最佳论文得主清华黄高团队提出首篇动态网络综述,全面回顾动态网络的发展!
R语言Kolmogorov-Smirnov检验比较两个样本是否来自同一个分布:ks.test函数执行Kolmogorov-Smirnov检验比较两个样本是否来自同一个分布
外设篇:按键和CPU的中断系统
Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集
[C language] bubble sort upgraded version --- applicable to any type
开放科学背景下的科学数据开放共享:国家青藏高原科学数据中心的实践
flinksql读取kafka数据报错
Dynamic memory management (malloc, free, calloc, realloc, flexible array)
【单片机仿真项目】数码管(proteus原理图+keil代码)
Custom type: structure, enumeration, union
thymeleaf在网页中上传文件
Play with makefile files
grpc设置连接存活时间及服务端健康检查
利用wget下载文件和网页
#yyds干货盘点# 解决名企真题:罪犯转移
uva1450
C traps and defects Chapter 2 syntax "traps" 2.5 function calls
Yyds dry goods inventory # solve the real problem of famous enterprises: Criminal transfer
Peripherals: SD card and other external memory devices
Form Data与Request Payload,你真的了解吗?