当前位置:网站首页>Unity 实现简单画板画画功能(笔记)
Unity 实现简单画板画画功能(笔记)
2022-07-27 21:05:00 【X-q-X】
一、搭好场景
- 创建一个plan
- 摄像机调成正交摄像机
- 创建三个cube,附上材质
- 再创建一个cube,找个色板,
- 创建一个脚本,挂在非失活物体上
- 创建一个slider,放在旁边

二、写代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Draw : MonoBehaviour {
LineRenderer line;
Material mat;
public Slider slider;
int num = 0;//总共画画点数
Color c;
// Use this for initialization
void Start () {
slider.value = 0.1f;
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
if (Input.GetMouseButtonDown(0))
{
if (c==null)
{
return;
}
GameObject obj = new GameObject();
line= obj.AddComponent<LineRenderer>();
line.material.color= c;
line.widthMultiplier = slider.value;//宽度
line.SetPosition(0,hit.point);
line.SetPosition(1, hit.point);
num = 0;
}
if (Input.GetMouseButton(0))
{
num++;
line.positionCount = num;
line.SetPosition(num - 1, hit.point+Vector3.up*0.2f);
}
if (Input.GetMouseButtonDown(1))
{
StartCoroutine(ChangeColor());
}
}
}
IEnumerator ChangeColor()
{
yield return new WaitForEndOfFrame();
Texture2D texture2D = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,true);
texture2D.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture2D.Apply();
c = texture2D.GetPixel((int)Input.mousePosition.x, (int)Input.mousePosition.y);
}
}
三、效果
Unity 画板
边栏推荐
- ZCMU--1720: 死亡如风,我要装逼
- Redis 哈希Hash底层数据结构
- Zabbix4.0 uses SNMP agent to monitor vcenter6.5
- Join hands with Changjiang storage, jiangbolong launches the world's smallest expansion card
- 重新定义分析 - EventBridge 实时事件分析平台发布
- 疫情之下,台积电一季度增长超预期,7nm占比35%!二季度或创新高
- [C language] address book (dynamic version)
- 编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
- Is it really hard to understand? What level of cache is the recyclerview caching mechanism?
- 2022/7/24-7/25
猜你喜欢

29. Learn the stacked column chart of highcharts using percentage

Huawei Hongmeng 3 was officially released, and this security feature has solved a major pain point

Normality of confidence interval

NDK series (6): let's talk about the way and time to register JNI functions

Character stream learning 14.3

My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
![[image defogging] image defogging based on dark channel and non-mean filtering with matlab code](/img/44/6120682f9571f6ad35f8b9249b7fea.png)
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code

Redis 哈希Hash底层数据结构

主数据管理理论与实践

2022年土木,建筑与环境工程国际会议(ICCAEE 2022)
随机推荐
NDK series (6): let's talk about the way and time to register JNI functions
Redis hash underlying data structure
My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
Reinforcement learning - pytorch realizes advantage actor critical (A2C)
Redis的分布式锁
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
三次握手的Socket交互流程
The technology of applet container is very promising, which can greatly improve the efficiency of mobile R & D
Those "experiences and traps" in the data center
29. Learn the stacked column chart of highcharts using percentage
What are the advantages of Tita's OKR system over other similar products or shared documents?
为什么需要等待计时2MSL?
After returning to mixlab for three days, "creative team" cured my spiritual internal friction
The share price soared 180.46%! Shanghai silicon industry, the leader of domestic large silicon wafers, is listed: the cumulative net profit in recent four years is less than 60million
Smartrefresh nested multiple recycleview sliding conflicts and incomplete layout display
数据中台的那些“经验与陷阱”
Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation
四次挥手的Socket交互流程
真的很难理解?RecyclerView 缓存机制到底是几级缓存?
Elk log analysis system installation and deployment