IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 游戏开发 -> 常用核心类知识点 -> 正文阅读

[游戏开发]常用核心类知识点

? ? ? ? //移动
? ? ? ? //属性

? ? ? ? transform.position = new Vector3(2, 0, 0);
? ? ? ? transform.position = Vector3.right * 2;
? ? ? ? //方法
? ? ? ? transform.Translate(2, 0, 2);
? ? ? ? transform.Translate(new Vector3(2, 2, 2));
? ? ? ? transform.Translate(Vector3.one * 2);

? ? ? ? //旋转
? ? ? ? transform.rotation = Quaternion.Euler(2, 2, 2);
? ? ? ? transform.Rotate(new Vector3(0, 45, 0));

? ? ? ? //缩放
? ? ? ? //属性

? ? ? ? transform.localScale = Vector3.one * 2;


//立方体围绕球旋转 ?Update运行 ? RotateAround//围绕旋转
? ?transform.RotateAround(qiu.position, Vector3.up, 1);


//向量加法
transform.position = B1.position + B2.position;
public GameObject B1;//GameObjeect游戏对象?
public GameObject B2;
//gameObject脚本对象
transform.position = B1.transform.position + B2.transform.position;


//随机数
? ? ? ? float a = Random.value;
? ? ? ? print(a);
? ? ? ? int b = Random.Range(1, 3);
? ? ? ? print(b);
? ? ? ? float c = Random.Range(1.0f, 3.0f);
? ? ? ? print(c);


//在游戏场景中的随机x位置克隆一个立方体
? ?float x = Random.Range(1f, 3f);
? ?Vector3 p = new Vector3(x, 3, 3);
? ?Instantiate(cube, p, Quaternion.identity);


//3秒倒计时
? ?float timer = 4f;
? ?public Text tap;
?void Update()
? ? {
? ? ? ? timer -= Time.deltaTime;
? ? ? ? if (timer<=1)
? ? ? ? {
?? ?tap.text = "Go"; ? ?
? ? ? ? }
? ? ? ? else
? ? ? ? {
?? ?tap.text = ((int)timer).ToString();
? ? ? ? }
? ? }


//通过游戏对象名称查找游戏对象
GameObject g = GameObject.Find("Cube");
g.transform.position = new Vector3(0, 45, 0);//绕Y轴旋转45度角
//通过标签名称查找游戏对象
GameObject g2 = GameObject.FindWithTag("Player");
g2.transform.localScale = Vector3.one * 2; //整体放大2倍


//通过游戏对象名称查找对象摄像机
GameObject go = GameObject.Find("Main Camera");
//添加Four脚本
go.AddComponent<Six>();
//获取摄像机上面的脚本
Six six = go.GetComponent<Six>();
print(six.a);


//协程
//游戏开始3秒后克隆一个立方体,再间隔5秒后依次克隆一个立方体
Coroutine c;//停止协程
void Start(){
StartCoroutine("P");
}
IEnumerator P()
{
? ?yield return new WaitForSeconds(5f);
? ?Instantiate(cube);
StopCoroutine(c);//停止协程
? ? ? ? while (true)
? ? ? ? {
?? ?yield return new WaitForSeconds(5f);
?? ?Instantiate(cube);
? ? ? ?}
?}
void Update () {
?? ??? ? //按下B键,每隔1秒打印一个数字
? ? ? ? if (Input.GetKeyDown(KeyCode.B))
? ? ? ? {
?? ??? ??? ?StartCoroutine("KeyDown");
? ? ? ? }
?? ?}
?? ?IEnumerator KeyDown1()
? ? {
? ? ? ? for (int i = 0; i < 10; i++)
? ? ? ? {
?? ?yield return new WaitForSeconds(1f);
?? ?print(i);
? ? ? ?}
? ? }


WSAD
//查找Horizontal ?Vertical:Edit---->Project Settings-Input
? ? ? ? float h = Input.GetAxis("Horizontal");//水平轴
? ? ? ? float v = Input.GetAxis("Vertical");//垂直轴
? ? ? ? Vector3 p = new Vector3(h, 0, v);
? ? ? ? ?transform.Translate(p * Time.deltaTime * speed);


? ? public void GetMessage(GameObject g)脚本都要挂在同一个地方??
? ? {
? ? ? ? print(g.name);
? ? }?
? ? public void GetMessage(string s)脚本分开挂在两个地方
? ? {
? ? ? ? print(s);
? ? }
? ? public void GetMessage(bool b)
? ? {
? ? ? ? print(b.ToString());
? ? }


//自己
SendMessage("GetMessage", this.gameObject, SendMessageOptions.RequireReceiver); ? SendMessage:发送消息
//父级和自己
SendMessageUpwards("GetMessage","father", ?SendMessageOptions.RequireReceiver); ? SendMessageUpwards:向上发送消息
//子级和自己
BroadcastMessage("GetMessage", "son", SendMessageOptions.RequireReceiver); ? ?BroadcastMessage:广播消息


//按下空格键使父级变成红黄色
?? ?void Update () {
? ? ? ? if (Input.GetKeyDown(KeyCode.Space))
? ? ? ? {
?? ?SendMessageUpwards("ChangColor", "red", SendMessageOptions.RequireReceiver); ? ?SendMessageUpwards:向上发送消息
? ? ? ? }
? ? }


void ChangColor(string color)
? ? {
? ? ? ? if (color.Equals("red"))
? ? ? ? {
? ? ? ? ? ? ? transform.GetComponent<MeshRenderer>().materials[0].color=Color.yellow; //通过获取组件,在点击属性
? ? ? ? }
? ? }

  游戏开发 最新文章
6、英飞凌-AURIX-TC3XX: PWM实验之使用 GT
泛型自动装箱
CubeMax添加Rtthread操作系统 组件STM32F10
python多线程编程:如何优雅地关闭线程
数据类型隐式转换导致的阻塞
WebAPi实现多文件上传,并附带参数
from origin ‘null‘ has been blocked by
UE4 蓝图调用C++函数(附带项目工程)
Unity学习笔记(一)结构体的简单理解与应用
【Memory As a Programming Concept in C a
上一篇文章      下一篇文章      查看所有文章
加:2022-05-24 18:32:01  更:2022-05-24 18:32:27 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/20 22:37:43-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码