how can i change the color of line renderer
i am new to unity i have set the width and color for the line that should appear when i swipe the screen..but its not working,dont know whether my code is wrong
now i am getting a pink color line while swiping on the screen.how can i change that color to white. also is it possible to reduce the width of line...
using UnityEngine;
using System.Collections;
public class LinesHandler : MonoBehaviour
{
public Color c1 = Color.yellow;
public Color c2 = Color.red;
private GameObject lineGO;
private LineRenderer lineRenderer;
private int i = 0;
void Start()
{
lineGO = new GameObject("Line");
lineGO.AddComponent<LineRenderer>();
lineRenderer = lineGO.GetComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Mobile/Particles/Additive"));
//lineRenderer.SetColors(c1, c2);
lineRenderer.SetWidth(0.05F, 0);
lineRenderer.SetVertexCount(0);
}
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Moved)
{
lineRenderer.SetVertexCount(i+1);
Vector3 mPosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 15);
lineRenderer.SetPosition(i, Camera.main.ScreenToWorldPoint(mPosition));
i++;
/* Add Collider */
BoxCollider bc = lineGO.AddComponent<BoxCollider>();
bc.transform.position = lineRenderer.transform.position;
bc.size = new Vector3(0.1f, 0.1f, 0.1f);
}
if(touch.phase == TouchPhase.Ended)
{
/* Remove Line */
lineRenderer.SetVertexCount(0);
i = 0;
/* Remove Line Colliders */
BoxCollider[] lineColliders = lineGO.GetComponents<BoxCollider>();
foreach(BoxCollider b in lineColliders)
{
Destroy(b);
}
}
}
}
}
Answer by arjunh · Oct 05, 2016 at 01:13 PM
the shader mentioned in the code is not present in the assets..so default pink color gets assigned
instead of 18th line lineRenderer.material = new Material(Shader.Find("Mobile/Particles/Additive"));
you can use - renderer.material.color = Color.white;
Your answer
![](https://koobas.hobune.stream/wayback/20220612094038im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Issue with trail renderer alignment 0 Answers
Looking for a specific page in documentation for Unity3D 0 Answers
how to rotate y axis while circular motion,How to rotate while circular motion 0 Answers
i have used an image on my game how can i pop up a new image when the first image is clicked 0 Answers
C# 3D Collider Without Fixed Points or use Mesh Filter Instead? 0 Answers