当前位置:网站首页>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层)
边栏推荐
- How to identify fake reptiles?
- How to debug TestCafe
- Performance optimization: remember a tree search interface optimization idea
- 角色妆容的实现
- VOT2021比赛简介
- 利用反射实现一个管理对象信息的简单框架
- spark reports an error OutOfMemory "recommended collection"
- 高通cDSP简单编程例子(实现查询高通cDSP使用率、签名),RK3588 npu使用率查询
- One thing to say, is outsourcing company worth it?
- Federated Learning: Multi-source Knowledge Graph Embedding in Federated Scenarios
猜你喜欢
Qualcomm cDSP simple programming example (to query Qualcomm cDSP usage, signature), RK3588 npu usage query
AI 自动写代码插件 Copilot(副驾驶员)
STM32 full series development firmware installation guide under Arduino framework
架构实战营模块八作业
二叉树非递归遍历
What's wrong with the sql syntax in my sql
21. Support Vector Machine - Introduction to Kernel Functions
Count characters in UTF-8 string function
Realization of character makeup
How to identify fake reptiles?
随机推荐
MATLAB program design and application 2.4 Common internal functions of MATLAB
Architecture Battalion Module 8 Homework
grep command written test questions
idea中搜索具体的字符内容的快捷方式
Shell 脚本 快速入门到实战 -02
Summary of the classic drawing method of histogram
Istio introduction
ThreadLocal
Linux environment redis cluster to build "recommended collection"
一款国外开发的高质量WordPress下载站模板主题
HTC使用官方固件作为底包制作rom卡刷包教程
A few permanent free network transmission, convenient and simple (Intranet through tutorials)
【核心概念】图像分类和目标检测中的正负样本划分以及架构理解
find prime numbers up to n
sqlite3简单操作
统计UTF-8字符串中的字符函数
useragent online lookup
第六章
The latest masterpiece!Alibaba just released the interview reference guide (Taishan version), I just brushed it for 29 days
【愚公系列】2022年07月 Go教学课程 025-递归函数