I want to draw lines using the Linerenderer only in the game view window.
I'm using Debug.DrawLine but only drawing Red lines but for some reason when the Linerenderer draw a line/s one of the Linerender lines is yellow it seems the green linerenderer is getting on the red one in the scene view window.
Debug.DrawLine(Input.mousePosition, hit.transform.position, Color.red);
Is there a way to avoid it ? So Debug.DrawLine will draw only in sceneview and the Linerenderer will draw only in the game view window ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateObjects : MonoBehaviour
{
public GameObject[] objectsToRotate;
public float speed = 0.1f;
public Vector3 spinDirection;
public bool useMouse = false;
public bool automaticSpin = false;
public LineRenderer linerendererPrefab;
List<LineRenderer> lrs = new List<LineRenderer>();
// Use this for initialization
void Start()
{
for(int i = 0; i < objectsToRotate.Length; i++)
{
var lr = Instantiate(linerendererPrefab);
lrs.Add(lr);
}
}
// Update is called once per frame
void Update()
{
if (objectsToRotate.Length > 0)
{
for (int i = 0; i < objectsToRotate.Length; i++)
{
var hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(Input.mousePosition), 100.0f);
for (int x = 0; x < hits.Length; x++)
{
RaycastHit hit = hits[x];
if (hit.collider.name == objectsToRotate[i].name)
{
objectsToRotate[i].transform.Rotate(1, 1, 1);
Debug.DrawLine(Input.mousePosition, hit.transform.position, Color.red);
SpawnLineGenerator(Input.mousePosition, hit.transform.position, false);
}
}
if(hits.Length == 0)
SpawnLineGenerator(new Vector3(0,0,0), new Vector3(0,0,0), true);
if (useMouse == true)
{
if (Input.GetMouseButton(0))
{
Rotate(i);
}
}
else
{
Rotate(i);
}
}
}
private void Rotate(int i)
{
if (automaticSpin == true)
{
objectsToRotate[i].transform.Rotate(1, 1, 1);
}
}
void SpawnLineGenerator(Vector3 start, Vector3 end, bool reset)
{
for(int i = 0; i < lrs.Count; i++)
{
if (reset)
{
lrs[i].SetPosition(0, start);
lrs[i].SetPosition(1, end);
}
else
{
lrs[i].SetPosition(0, start);
lrs[i].SetPosition(1, end);
}
}
}
}