当前位置:网站首页>Unity - LineRenderer show a line
Unity - LineRenderer show a line
2022-07-31 22:09:00 【Tiantian up UT】
01 新建一个line的控件
02 Add controls to scripts
03 Control the color of the lines via script,粗细,位置
using UnityEngine;
using System.Collections;
using System.Threading;
using UnityEngine.UI;
public class Demo : MonoBehaviour
{
//游戏对象,Here is the line segment object
public GameObject LineRenderGameObject;
//Line segment renderer
private LineRenderer lineRenderer;
//两个按钮
public Button btn1;
public Button btn2;
[System.Obsolete]
void Start()
{
//通过游戏对象,GetComponent方法 传入LineRenderer
//Just given beforelineRenderer properties added by game objects
//With this object it is possible to render line segments for the game world
lineRenderer = LineRenderGameObject.GetComponent("LineRenderer") as LineRenderer;
if (lineRenderer != null)
{
//设置线的颜色
lineRenderer.startColor = new Color(0, 0, 255, 1);
lineRenderer.endColor = new Color(0, 0, 255, 1);
//Sets the width of the line at the start and end of the line,值越大越宽
lineRenderer.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f;
//Draw two lines,take the starting point(0)和终点(1),The position of the start and end points is that of the buttonposition,直接获取到了ugui的按钮位置,Convert it to world coordinateslineRenderer
lineRenderer.SetPosition(0, btn1.transform.position);
lineRenderer.SetPosition(1, btn2.transform.position);
Debug.Log("btn1.transform.position = "+ btn1.transform.position);
}
}
}
04 设置layer看linerender和canvasWho is in front and behind.(因为linerender不是2d物体,不在canvas层)
边栏推荐
- Embedded development has no passion, is it normal?
- Book of the Month (202207): The Definitive Guide to Swift Programming
- [Open class preview]: Research and application of super-resolution technology in the field of video image quality enhancement
- AI automatic code writing plugin Copilot (co-pilot)
- 【Yugong Series】July 2022 Go Teaching Course 025-Recursive Function
- Architect 04 - Application Service Encryption Design and Practice
- One thing to say, is outsourcing company worth it?
- OSPFv3的基本配置
- BM5 合并k个已排序的链表
- Istio introduction
猜你喜欢
[Code Hoof Set Novice Village 600 Questions] Leading to the combination of formulas and programs
高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
ReentrantLock原理(未完待续)
Architect 04 - Application Service Encryption Design and Practice
高效并发:Synchornized的锁优化详解
The latest masterpiece!Alibaba just released the interview reference guide (Taishan version), I just brushed it for 29 days
STM32 full series development firmware installation guide under Arduino framework
The principle of ReentrantLock (to be continued)
Unity-通过预制件和克隆方法动态实现各个UGUI下控件的创建和显示
Count characters in UTF-8 string function
随机推荐
高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
角色妆容的实现
Collation of knowledge points in Ningbo University NBU IT project management final exam
Judging decimal points and rounding of decimal operations in Golang
Bika LIMS open source LIMS set - use of SENAITE (detection process)
Chapter VII
PCB叠层设计
grep命令 笔试题
返回一个零长度的数组或者空的集合,不要返回null
"The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
flowable workflow all business concepts
高效并发:Synchornized的锁优化详解
Thymeleaf是什么?该如何使用。
sqlite3简单操作
Returns a zero-length array or empty collection, do not return null
Apache EventMesh distributed event-driven multi-runtime
基于RT1052 Aworks nanopb string 类型固定长度使用方式(二十七)
Audio alignment using cross-correlation
NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores
BM3 将链表中的节点每k个一组翻转