Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by arjunh · Oct 05, 2016 at 11:18 AM · 3dunity5linerenderer

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);
             }
         }
     }
 }
     }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

82 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

can anyone tell what this script actually does 0 Answers

Unity multiplayer line rendering 0 Answers

drag gameobject from ui scroll panel to 3d space 0 Answers

Change rotation sensitivity of Oculus Rift? 0 Answers

Trying find a solution to draw on seams with Ink Painter(Free Real-Time Texture Painting Asset) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges