当前位置:网站首页>使用Unity做一个艺术字系统
使用Unity做一个艺术字系统
2022-07-27 04:07:00 【极客范儿】
为了熟悉CaptureScreen方法,做一个艺术字系统。
首先声明一个公共变量toward,以便在书脚本Cature_Use中调用,然后给另一个变量delays赋予一个随机值,以便每个小球的运动显得更加真实
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Capture_Use_Sub : MonoBehaviour
{
//物体移动的目标位置
public Vector3 toward;
float delays;
void Start()
{
//获取一个随机值
delays = Random.Range(2.0f, 4.0f);
}
void Update()
{
//通过更改物体位置来达到物体运动的效果
transform.position = Vector3.MoveTowards(transform.position, toward, delays);
}
}
接着创作主程序
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Capture_Use : MonoBehaviour
{
//td:用来指向屏幕截图
Texture2D td = null;
//txt_bg:用来指向文本输入的北京图片
//可以指向一张纯色的图片,也可以自定义一个纯色的北京
//本程序自定义了一个纯色的背景
Texture2D txt_bg;
//txt_w和txt_h用来记录文本框的宽度和高度
int txt_w, txt_h;
//my_save_path:用来记录截图的保存路径
string my_save_path = "";
//show_txt:用来记录输入的文本
string show_txt = "在此输入";
//myh_colors:用来记录文本输入框的纹理颜色
Color[] colors;
// _w, _h;用来记录my_color的宽度和高度
int _w, _h;
//step:用来记录当前状态,step共有4种状态
//step=0时,是等待状态,等待在文本框中输入文本
//step=1时,即点击“确定”按钮后,生成截图并保存
//step=2时,读取截图信息
//step=3时,是对读取的截图信息进行有选择的提取,并生成想要展示的北荣
int step = 0;
//go:用来指向拼字所用物体对象
public GameObject go;
//gos:用来记录所有的go对象
GameObject[] gos;
//gos_max用来记录gos的最大数量
int gos_max;
//gos_cur用来记录gos当前数量
int gos_cur = 0;
//is_show:用来记录图像矩阵中某个点是否需要展示物体
bool[,] is_show;
void Start()
{
//初始化文本框的宽度和高度
txt_w = 200;
txt_h = 80;
//初始化截取区间的大小,维乐避免边界识别错误,其值应该比文本框的宽度和高度少几个像素
_w = txt_w;
_h = txt_h;
_w -= 5;
_h -= 5;
//自定义txt_bg纹理
txt_bg = new Texture2D(txt_w, txt_h);
Color[] tdc = new Color[txt_w * txt_h];
for (int i = 0; i < txt_w * txt_h; i++)
{
//所用像素点颜色相同
tdc[i] = Color.white;
}
txt_bg.SetPixels(0, 0, txt_w, txt_h, tdc);
is_show = new bool[_h, _w];
//初始化gos_max,其值大小为txt_w * txt_h的三分之一
gos_max = _w * _h / 3;
//实例化gos,使其随机分布_w, _h的区间内
gos = new GameObject[gos_max];
for (int i = 0; i < gos_max; i++)
{
gos[i] = (GameObject)Instantiate(go, new Vector3(Random.value * _w, Random.value * _h, 10.0f), Quaternion.identity);
gos[i].GetComponent<Capture_Use_Sub>().toward = gos[i].transform.position;
}
//存储出事界面截图
my_save_path = Application.persistentDataPath;
ScreenCapture.CaptureScreenshot(my_save_path + "/test02.png");
}
void Update()
{
}
}
边栏推荐
- Post analysis of Data Analyst
- Prometheus Node Exporter 常用监控指标
- The data in echart histogram is displayed at the top of the chart
- How CentOS installs mysqldump
- [small sample segmentation] msanet: multi similarity and attention guidance for boosting few shot segmentation
- 利用JSON类型在mysql中实现数组功能
- [C language] recursively explain the tower of Hanoi problem
- spark练习案例(升级版)
- els 方块显示原理
- 数据库泰斗王珊:努力创新,精心打磨优质的数据库产品
猜你喜欢

人很话不多,工程师不耍嘴皮子

Ant JD Sina 10 architects 424 page masterpiece in-depth distributed cache from principle to practice pdf

好用的shell快捷键

Understand kingbasees V9 in one picture

Influxdb basic understanding

Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)

Word/Excel 固定表格大小,填写内容时,表格不随单元格内容变化

Convolution neural network -- a detailed introduction to convolution of 24 bit color images

Practice of microservice in solving Library Download business problems

Elastic open source community: Developer Recruitment
随机推荐
Shell中的文本处理工具、cut [选项参数] filename 说明:默认分隔符是制表符、awk [选项参数] ‘/pattern1/{action1}filename 、awk 的内置变量
2022杭电多校联赛第三场 题解
BSN IPFs (interstellar file system) private network introduction, functions, architecture and characteristics, access instructions
Influxdb basic understanding
Post analysis of Data Analyst
grid布局
标准C语言13
Brightcove任命Dan Freund为首席营收官
你了解微信商户分账吗?
ISG指数显示,亚太区IT和商业服务市场在第二季度出现大幅下滑
F - Pre-order and In-order(Atcoder 255)
Elastic certification test: 30 day FastPass Study Guide
Using webmvcconfigurer to intercept interface requests is being enhanced (with source code)
【day02】数据类型转换、运算符、方法入门
[final review of software engineering] knowledge points + detailed explanation of major problems (E-R diagram, data flow diagram, N-S box diagram, state diagram, activity diagram, use case diagram...)
Introduction to regular expressions of shell, general matching, special characters: ^, $,., * Character range (brackets): [], special characters: \, matching mobile phone number
Detailed explanation of TCP protocol knowledge
[day02] Introduction to data type conversion, operators and methods
js修改对象数组的key值
JS modify the key value of the object array