Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by WUSHUANGDAWANG · Jul 16, 2019 at 04:14 AM · line renderer

line renderer to draw multiple lines

I want to draw three separate lines with line renderer, but I can only see one when I run the program. How can I make all of them appear? Thanks!

enter code here` using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Keep_dist : MonoBehaviour { public GameObject eye; public GameObject Pikachu; public Vector3 a; public Vector3 b; public Transform obj1_s; public Transform obj1_e; public LineRenderer line1; public Transform obj2_s; public Transform obj2_e; public LineRenderer line2; public Transform obj3_s; public Transform obj3_e; public LineRenderer line3; // Start is called before the first frame update void Start() { line1 = eye.GetComponent(); line2 = eye.GetComponent(); line3 = eye.GetComponent(); }

 public void MoveGameObject()
 {
     Pikachu.transform.position = b;
 }

 // Update is called once per frame
 void FixedUpdate()
 {
     a = eye.transform.position;
     b = Pikachu.transform.position;
     b.x = a.x + 1;
     b.y = a.y;
     b.z = a.z - 3;
     MoveGameObject();
     //print(a.ToString());
     //print(b.ToString());
     line1.SetPosition(0, obj1_s.position);
     line1.SetPosition(1, obj1_e.position);
     line2.SetPosition(0, obj2_s.position);
     line2.SetPosition(1, obj2_e.position);
     line3.SetPosition(0, obj3_s.position);
     line3.SetPosition(1, obj3_e.position);
 }

}

Comment
Add comment · Show 1
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
avatar image WUSHUANGDAWANG · Jul 16, 2019 at 04:14 AM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class $$anonymous$$eep_dist : $$anonymous$$onoBehaviour
 {
     public GameObject eye;
     public GameObject Pikachu;
     public Vector3 a;
     public Vector3 b;
     public Transform obj1_s;
     public Transform obj1_e;
     public LineRenderer line1;
     public Transform obj2_s;
     public Transform obj2_e;
     public LineRenderer line2;
     public Transform obj3_s;
     public Transform obj3_e;
     public LineRenderer line3;
     // Start is called before the first frame update
     void Start()
     {
         line1 = eye.GetComponent<LineRenderer>();
         line2 = eye.GetComponent<LineRenderer>();
         line3 = eye.GetComponent<LineRenderer>();
     }
 
     public void $$anonymous$$oveGameObject()
     {
         Pikachu.transform.position = b;
     }
 
     // Update is called once per frame
     void FixedUpdate()
     {
         a = eye.transform.position;
         b = Pikachu.transform.position;
         b.x = a.x + 1;
         b.y = a.y;
         b.z = a.z - 3;
         $$anonymous$$oveGameObject();
         //print(a.ToString());
         //print(b.ToString());
         line1.SetPosition(0, obj1_s.position);
         line1.SetPosition(1, obj1_e.position);
         line2.SetPosition(0, obj2_s.position);
         line2.SetPosition(1, obj2_e.position);
         line3.SetPosition(0, obj3_s.position);
         line3.SetPosition(1, obj3_e.position);
     }
 }
 

1 Reply

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

Answer by Casiell · Jul 16, 2019 at 05:59 AM

All those eye.GetComponent() lines are returning the same LineRenderer. You should either assign those manually (better option, but remember to remove the assignment from Start) or use GetComponents which will give you all LineRenderers from the object.

Also in case this is your problem: one LineRenderer can only draw one line! It can be a curve, but it's a singular line with only two ends

Comment
Add comment · Show 1 · 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
avatar image WUSHUANGDAWANG · Jul 19, 2019 at 01:03 AM 0
Share

Thank you, I fixed my problem. Really appreciate it.

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

109 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 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

How can I increase the view-distance of a trail renderer? 1 Answer

why can't Line Renderer catch movement of camera? 0 Answers

Draw out Line in C# 0 Answers

How to draw two lines at the same time that keeps overlapping each other? 1 Answer

Lightning Using A Line Renderer 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