当前位置:网站首页>Unity implements simple Sketchpad drawing function (notes)
Unity implements simple Sketchpad drawing function (notes)
2022-07-27 23:55:00 【X-q-X】
List of articles
One 、 Set up the scene
- Create a plan
- Turn the camera into an orthogonal camera
- Create three cube, Attach material
- Create another cube, Find a palette ,
- Create a script , Hang on a non inactivated object
- Create a slider, Put it aside

Two 、 Write code
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;// Total painting points
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;// Width
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);
}
}
3、 ... and 、 effect
Unity Drawing board
边栏推荐
- 如果我们是那晚负责修复 B 站崩了的开发人员
- The 4-hour order exceeds 20000+, claiming to be "the most luxurious in a million". Is the domestic brand floating?
- New technology leads new changes in marketing of large and medium-sized enterprises, and UFIDA BiP CRM is launched!
- Zabbix4.0 uses SNMP agent to monitor vcenter6.5
- Latex中如何加粗字体 & 如何打出圆圈序号
- 【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)
- Error:svn: E155010: ‘/Users/.../Desktop/wrokspace/xxx‘ is scheduled for addition, but is missing
- Is it really hard to understand? What level of cache is the recyclerview caching mechanism?
- 2022夏暑假每日一题(五)
- Character stream learning 14.3
猜你喜欢

【12月海口】2022年第六届船舶,海洋与海事工程国际会议(NAOME 2022)

Bank marketing predicts the success rate of a customer's purchase of financial products

Redis 哈希Hash底层数据结构

Key points of data management

【zer0pts CTF 2022】 Anti-Fermat

Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation
![[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters](/img/05/7029eb1fe36d7ddab2640f07247c81.png)
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters

【zer0pts CTF 2022】 Anti-Fermat

JUC toolkit learning

Lua基础语法学习
随机推荐
Realize today's news website based on native JS
Which one is better to request to merge -- three skills of interface request merging, and the performance directly explodes the table
TFRecord的Shuffle、划分和读取
Why do I need to wait for 2msl?
Solve 5g pain points, Meizu 17 smart 5g fast and stable technology release
数据中台的那些“经验与陷阱”
Reinforcement learning - pytorch realizes advantage actor critical (A2C)
Latex中如何加粗字体 & 如何打出圆圈序号
Latex常用总结(2):输入矩阵(输入矩阵、对角阵、方程组等)
2022/7/26
Lua basic grammar learning
[GWCTF 2019]BabyRSA1
15million per day! BYD masks won a US $1billion order in California
Starfish OS X metabell strategic cooperation, metauniverse business ecosystem further
Construction and application of super large scale knowledge map of ants
Socket interaction process of three handshakes
真的很难理解?RecyclerView 缓存机制到底是几级缓存?
【zer0pts CTF 2022】 Anti-Fermat
JUC工具包学习
76000 people shut down! Toshiba announced the closure of all factories in Japan