Wanted to ask that how to destroy an object by using line renderer.
every time i swipe to the object i spawn, the line just behind the object and when i set ontriggerenter to them, the object wont be destroy.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LineFollow : MonoBehaviour {
int vertexcount;
public bool mousedown = false;
private LineRenderer line;
// Use this for initialization
void Start () {
line = GetComponent<LineRenderer> ();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
mousedown = true;
}
if (mousedown) {
line.positionCount = vertexcount + 1;
//line.SetVertexCount (vertexcount + 1);
Vector3 mousepos = Camera.main.ScreenToWorldPoint(new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 15f));
line.SetPosition (vertexcount, mousepos);
vertexcount++;
BoxCollider collider = gameObject.AddComponent<BoxCollider> ();
collider.transform.position = line.transform.position;
collider.size = new Vector3 (0.2f, 0.2f);
}
if (Input.GetMouseButtonUp (0)) {
vertexcount = 0;
line.positionCount = 0;
//line.SetVertexCount (0);
mousedown = false;
DestroyCollider ();
}
}
private void DestroyCollider()
{
BoxCollider[] box = GameObject.FindObjectsOfType<BoxCollider> ();
foreach (BoxCollider _box in box) {
Destroy (_box);
}
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "mons") {
Destroy (col.gameObject);
}
}
}
code updated, i add a collider inside the line renderer, but when i swipe to the object, nothing happen.