当前位置:网站首页>[unity technology accumulation] realize the mouse line drawing function &linerenderer
[unity technology accumulation] realize the mouse line drawing function &linerenderer
2022-07-19 11:40:00 【FYK0q0】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Painting : MonoBehaviour
{
private LineRenderer lineRenderer;
// Record point
private Vector3 nowPos;
// Line width
public float lineWidth = 0.5f;
// Set the material
public Material material;
private void Update()
{
// When the mouse is pressed, the starting position switches
if (Input.GetMouseButtonDown(0))
{
// Create an empty object and add components
GameObject obj = new GameObject();
lineRenderer = obj.AddComponent<LineRenderer>();
// Turn off automatic stitching
lineRenderer.loop = false;
// Set line width
lineRenderer.startWidth = lineWidth;
lineRenderer.endWidth = lineWidth;
// Set the number of points to 0
lineRenderer.positionCount = 0;
// Set line material
lineRenderer.material = material;
// Set the material to be affected by light
lineRenderer.generateLightingData = true;
}
// When drawing, the mouse is pressed all the time
if (Input.GetMouseButton(0))
{
lineRenderer.positionCount += 1;
// Record the mouse position
nowPos = Input.mousePosition;
// Set the cross section to 10
nowPos.z = 10;
// Set point
// Mouse position viewport coordinates into world coordinates
lineRenderer.SetPosition(lineRenderer.positionCount
- 1, Camera.main.ScreenToWorldPoint(nowPos));
}
}
}

边栏推荐
- NAT technology and NAT alg
- LeetCode 558. Intersection of quadtree
- Keras deep learning practice (14) -- r-cnn target detection from scratch
- 传输层 -------- TCP(一)
- 03-2、
- [PostgreSQL] PostgreSQL 15 optimizes distinct
- 委派雙親之類加載器
- Solve the problem that QQ mail and Thunderbird cannot log in to outlook
- How to change and reset forgotten root password in RHEL 9
- 《MySQL DBA封神打怪之路》专栏学习大纲
猜你喜欢

Docker install MySQL

Performance optimization @contented to reduce pseudo sharing

TCP拥塞控制详解 | 7. 超越TCP

【嵌入式单元测试】C语言单元测试框架搭建

Leetcode 1328. Destroy palindrome string (yes, solved)

Round table record: fireside dialogue -- how to realize innovation in Web3

From "passive" to "active", how can zeta technology help to upgrade "rfid2.0"?

02 - 3. Différences entre les pointeurs et les références

Redis分布式缓存-Redis集群

jconsole线程面板中的阻塞总数和等待总数(转)
随机推荐
常见分布式锁介绍
动态内存分配问题
TCP congestion control details | 7 Surpass TCP
LeetCode 558. Intersection of quadtree
What do you look at after climbing the wall? The most popular foreign website - website navigation over the wall
2022 National latest fire-fighting facility operator (intermediate fire-fighting facility operator) simulation test questions and answers
03-1. Inline function, auto keyword, typeID, nullptr
Robot development -- common simulation software tools
机器人开发--常用仿真软件工具
Powercli script performance optimization
Learning note 3 -- basic idea of machine learning in planning control
性能优化之@Contended减少伪共享
[untitled] CV learning 1 conversion
Deep learning for generic object detection: a survey
Learning outline of the column "MySQL DBA's magic road"
Some methods of early MCU encryption [get data in the comment area]
Microservice online specification
【多线程】JUC详解 (Callable接口、RenntrantLock、Semaphore、CountDownLatch) 、线程安全集合类面试题
A curated list of awesome Qt and QML
Opencv draw a black rectangle and write the serial number