- Home /
How to create a line render that will only start in a specific area.
So I created a line rendering script attached to the camera that creates a line by holding down the left mouse button and then releasing the left mouse button.
However, I want to restrict the player being able to actually create the line, unless they are clicking on top of a sprite (in this case a simple dot on the picture). I was thinking about using an event component on the sprite, but I am not sure how to then link it to the script. Am I approaching the problem incorrectly?
Answer by tormentoarmagedoom · Jun 07, 2018 at 07:54 AM
Good day.
If I understand, you want the player to be able to create lines, but only if starts from a GameObject?
Then you can use Raycasts. If the raycast is not hitting a object with some specific preoperty o specific tag, the line does not commence.
The event System is also a good was to do it. For example, this objects can change a bool variable at the LineGenerator script to know that you are cliking a object. OR you can make that the line generator script is inside all this objects, so each object generate "their own lines".
Good luck!
Thanks!
I solved the problem by adding 2 functions: "On$$anonymous$$ouseOver" and "On$$anonymous$$ouseExit" and creating a Boolean variable called: _overVertex like you said and made it equal to false by default.
I then added to the 2 functions:
void On$$anonymous$$ouseOver()
{
_overVertex = true;
}
void On$$anonymous$$ouseExit()
{
_overVertex = false;
}
After that, all I had to do was in the if statement in my update function, I placed another check to see if the _overVertex value was true like so:
if (Input.Get$$anonymous$$ouseButtonDown(0) && _overVertex == true)
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating a LineRenderer: its always null 2 Answers
c# code help -- events part 1 1 Answer
slowly rotate a object *need quick fix* 0 Answers