欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

unity實現(xiàn)屏幕上寫字效果

 更新時間:2019年07月16日 11:25:56   作者:人生若只如初見~~~  
這篇文章主要為大家詳細介紹了unity實現(xiàn)屏幕上寫字效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了unity實現(xiàn)屏幕上寫字效果的具體代碼,供大家參考,具體內(nèi)容如下

先建立一個RawImage,然后再在這個圖片上加個LineRenderer組件,再建個材質(zhì)球,把材質(zhì)球的Shader改成Particles/Additive,把材質(zhì)球拖給LineRenderer組件的Materials/Element 0(不拖也可以),最后再把代碼拖給空物體即可,代碼的Target是RawImage,下面的代碼

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class huaxian : MonoBehaviour 
{

private GameObject clone;
private LineRenderer line;
int i;

//帶有LineRender物體
public GameObject target;

void Start()
{
  Debug.Log("請開始寫字");
} 

// Update is called once per frame 
 void Update()
{
  if (Input.GetMouseButtonDown(0))
  {
    //實例化對象 
    clone = (GameObject)Instantiate(target, target.transform.position, Quaternion.identity);
    //獲得該物體上的LineRender組件 
    line = clone.GetComponent<LineRenderer>();
    //設(shè)置起始和結(jié)束的顏色 
    line.SetColors(Color.red, Color.blue);
    //設(shè)置起始和結(jié)束的寬度  
    line.SetWidth(0.2f, 0.1f);
    //計數(shù)  
    i = 0;
  }
   if (Input.GetMouseButton(0))
  {
    //每一幀檢測,按下鼠標(biāo)的時間越長,計數(shù)越多 
    i++;
    //設(shè)置頂點數(shù) 
    line.SetVertexCount(i);
    //設(shè)置頂點位置(頂點的索引,將鼠標(biāo)點擊的屏幕坐標(biāo)轉(zhuǎn)換為世界坐標(biāo)) 
    line.SetPosition(i - 1, Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 15)));
  }
 }
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論