- Home /
Triangle formed is still shown
I have three frame markers and there are three balls being shown above them.I have drawn a line between each two balls using lineRenderer thus forming a triangle. When I move the marker away from the camera view then the balls disappear(as should be) but the triangle is still displayed. How do I make the line also disappear when it can't find the ball or frame marker? I am coding in c# Please help guys Thanks :)
Disable the LineRenderer component, and it'll stop drawing a line.
Answer by Owen-Reynolds · Jul 11, 2014 at 03:35 PM
You're thinking about the problem the wrong way. The idea is for the human to think it's real, and that the lines wink out because it couldn't draw them. But, it's really just all faked, by you. There's no relationship to how easy something is in real life, to how hard it is for the computer to fake it.
You have code drawing three lines, connecting three balls. You want code for one line connecting two balls. Then, there are three possible pairs of two balls (AB, AC and BC,) so figure out how to make each of those lines.
Probably the 2-line code will be similar to the 3-line code, but simpler, or maybe not. Probably each of the connect-2-balls lines will be the same except for the variables. Or maybe not. There might be a nice way to combine all the code into one chunk the skips off-screen ball-lines. Or there might not be.
When you've got all three new 2-line codes written and tested, you just have to switch between them. If ball B goes off-screen, stopping running the 3-line code, and run the "make the AC line" code.
Answer by Tehnique · Jul 11, 2014 at 12:46 PM
As rutter said, you can disable the LineRenderer all together, or use .SetVertexCount(0) on it.
But I don't want all the lines to disappear.For example,if I remove one ball,then I still have two balls in the scene and a line should be drawn between the two.Only the lines for the removed ball should disappear. Thanks
Ah, well. When you remove the ball, call "SetVertexCount(number_of_remaining_balls)", then go through the remaining balls and call "SetPosition(ball[i].position)".
So for example:
//You removed ball 3, and you are left with 2 balls, held in the generic list "balls".
lineRenderer.SetVertexCount(balls.Count);
for(int i=0; i<balls.Count; i++)
{
lineRenderer.SetPosition(i, balls[i].position);
}
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
NullReferenceException: Object reference not set to an instance of an object 3 Answers
Making the delay actually work 1 Answer
Cloud recognition in Vuforia 0 Answers
Unity OpenCV integration 1 Answer