Skip to content

Instantly share code, notes, and snippets.

@fabian71
Created May 15, 2018 18:31
Show Gist options
  • Select an option

  • Save fabian71/e0d490f8ca4850d8b446c7d465315cfa to your computer and use it in GitHub Desktop.

Select an option

Save fabian71/e0d490f8ca4850d8b446c7d465315cfa to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LinhaScript : MonoBehaviour {
int numeroDeVertices = 0;
LineRenderer linha;
bool apertandoBotaoDoMouse = false;
// Use this for initialization
void Start () {
linha = GetComponent<LineRenderer>();
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
apertandoBotaoDoMouse = true;
}
if(Input.GetMouseButtonUp(0)){
apertandoBotaoDoMouse = false;
}
if(apertandoBotaoDoMouse){
CriarLinha();
}else{
DeletarLinha();
}
}
void CriarLinha() {
linha.SetVertexCount (numeroDeVertices + 1);
Debug.Log(Input.mousePosition);
Vector3 posicaoDoMouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
linha.SetPosition(numeroDeVertices, posicaoDoMouse);
numeroDeVertices++;
}
void DeletarLinha() {
numeroDeVertices = 0;
linha.SetVertexCount(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment