当前位置:网站首页>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层)


边栏推荐
- AI automatic code writing plugin Copilot (co-pilot)
- 请问我的这段sql中sql语法哪里出了错
- A shortcut to search for specific character content in idea
- MATLAB program design and application 2.4 Common internal functions of MATLAB
- 给定一个ip地址,子网掩码怎么算网络号(如何获取ip地址和子网掩码)
- 架构实战营模块八作业
- "The core concept of" image classification and target detection in the positive and negative samples and understanding architecture
- 老牌音乐播放器 WinAmp 发布 5.9 RC1 版:迁移到 VS 2019 完全重建,兼容 Win11
- Audio alignment using cross-correlation
- Write a database document management tool based on WPF repeating the wheel (1)
猜你喜欢

Getting Started with Tkinter

Memblaze released the first enterprise-grade SSD based on long-lasting particles. What is the new value behind it?

A shortcut to search for specific character content in idea

Redis综述篇:与面试官彻夜长谈Redis缓存、持久化、淘汰机制、哨兵、集群底层原理!...

登录业务实现(单点登录+微信扫码+短信服务)

PCB叠层设计

Bionic caterpillar robot source code

Audio alignment using cross-correlation

In Golang go-redis cluster mode, new connections are constantly created, and the problem of decreased efficiency is solved

NVIDIA has begun testing graphics products with AD106 and AD107 GPU cores
随机推荐
How to identify fake reptiles?
Basic Grammar Introduction of Carbon Tutorial (Tutorial)
leetcode 665. Non-decreasing Array 非递减数列(中等)
How to debug TestCafe
spark reports an error OutOfMemory "recommended collection"
LevelSequence source code analysis
The old music player WinAmp released version 5.9 RC1: migrated to VS 2019, completely rebuilt, compatible with Win11
grep command written test questions
Collation of knowledge points in Ningbo University NBU IT project management final exam
信息学奥赛一本通 1941:【07NOIP普及组】Hanoi双塔问题 | 洛谷 P1096 [NOIP2007 普及组] Hanoi 双塔问题
统计UTF-8字符串中的字符函数
Made with Flutter and Firebase!counter application
NVIDIA已经开始测试AD106和AD107 GPU核心的显卡产品
Douyin fetches video list based on keywords API
Recognize anomalies (you will understand after reading this)
idea中搜索具体的字符内容的快捷方式
Bionic caterpillar robot source code
Getting Started with Tkinter
Go mode tidy reports an error go warning “all” matched no packages
Structure of the actual combat battalion module eight operations