当前位置:网站首页>Unity-LineRenderer显示一条线
Unity-LineRenderer显示一条线
2022-07-31 21:33:00 【天添向上UT】
01 新建一个line的控件
02 把控件加入脚本
03 通过脚本控制线的颜色,粗细,位置
using UnityEngine;
using System.Collections;
using System.Threading;
using UnityEngine.UI;
public class Demo : MonoBehaviour
{
//游戏对象,这里是线段对象
public GameObject LineRenderGameObject;
//线段渲染器
private LineRenderer lineRenderer;
//两个按钮
public Button btn1;
public Button btn2;
[System.Obsolete]
void Start()
{
//通过游戏对象,GetComponent方法 传入LineRenderer
//就是之前给line游戏对象添加的渲染器属性
//有了这个对象才可以为游戏世界渲染线段
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);
//设置线的起点和终点的线的宽度,值越大越宽
lineRenderer.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f;
//画出两条线,取起点(0)和终点(1),起点和终点的位置就是按钮的position,直接获取到了ugui的按钮位置,把它转换为了世界坐标给到了lineRenderer
lineRenderer.SetPosition(0, btn1.transform.position);
lineRenderer.SetPosition(1, btn2.transform.position);
Debug.Log("btn1.transform.position = "+ btn1.transform.position);
}
}
}
04 设置layer看linerender和canvas谁在前面和后面。(因为linerender不是2d物体,不在canvas层)
边栏推荐
- renderjs usage in uni-app
- Shell 脚本 快速入门到实战 -02
- UVM RAL model and built-in seq
- AI automatic code writing plugin Copilot (co-pilot)
- BM3 将链表中的节点每k个一组翻转
- Chapter Six
- ECCV 2022 Huake & ETH propose OSFormer, the first one-stage Transformer framework for camouflaging instance segmentation!The code is open source!...
- OSPFv3的基本配置
- rj45对接头千兆(百兆以太网接口定义)
- Write a database document management tool based on WPF repeating the wheel (1)
猜你喜欢
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
Short-circuit characteristics and protection of SiC MOSFETs
A shortcut to search for specific character content in idea
Basic configuration of OSPFv3
[Intensive reading of the paper] iNeRF
The principle of ReentrantLock (to be continued)
Summary of the classic drawing method of histogram
高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
Socket回顾与I/0模型
[Code Hoof Set Novice Village 600 Questions] Merge two numbers without passing a character array
随机推荐
PCB stackup design
-xms -xmx(information value)
MATLAB program design and application 2.4 Common internal functions of MATLAB
Apache EventMesh distributed event-driven multi-runtime
【愚公系列】2022年07月 Go教学课程 025-递归函数
【AcWing】The 62nd Weekly Match 【2022.07.30】
The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
Redis Overview: Talk to the interviewer all night long about Redis caching, persistence, elimination mechanism, sentinel, and the underlying principles of clusters!...
Getting Started with Tkinter
Embedded development has no passion, is it normal?
pytorch lstm时间序列预测问题踩坑「建议收藏」
BM3 将链表中的节点每k个一组翻转
利用反射实现一个管理对象信息的简单框架
Made with Flutter and Firebase!counter application
Thymeleaf是什么?该如何使用。
Financial profitability and solvency indicators
c语言解析json字符串(json对象转化为字符串)
The whole network is on the verge of triggering, and the all-round assistant for content distribution from media people - Rongmeibao
GateWay implements load balancing
Realization of character makeup