Search Unity

Randomly Draw the rectangle and fill it

Discussion in 'Scripting' started by Riviere Delta, Aug 26, 2014.

  1. Riviere Delta

    Riviere Delta

    Joined:
    Aug 26, 2014
    Posts:
    8
    Hi,

    I am trying to build a project where player moves and draw lines randomly on a grid.which can create rectangles. I want to fill the rectangle with color or texture when the player completes the rectangle. How do I measure that all four edges of rectangle are drawn to fill the color? Its kind of a effect like a Sega Zoom game.

    I am using arrow keys to control player movements. and trail renderer to draw lines.

    Please help me to resolve this.

    thanks in advance.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Please do not double (Triple!) post the exact same question. I expect you question was rejected because you aren't really asking for help, you are asking for a how-to. From scratch.

    I will make several suggestions.
    Trail renderer probably isn't the best choice, if the player repeatedly goes over the same line again and again and again, you get a ton of wasted polygons.
    To create a filled area, you can Instantiate a mesh object, or use CreatePrimitive to make a quad, then apply texture.
    To get the gameplay aspect working, you'll probably want to have a class for the rectangle structure, with a 4 booleans, for the status of each side. When the player completes a traversal of one side, set the boolean true, and check if all 4 are now true.
    To determine if a side has been traversed, I'd probably create a grid of nodes at the corners, when the player reaches a node, the side between it and the previously visited node is complete.
     
  3. Riviere Delta

    Riviere Delta

    Joined:
    Aug 26, 2014
    Posts:
    8
    Thank you for the information. And sorry if the same post has been posted several times. I will take care of it now on.
    I guess i can continue working with possibilities/options suggested by you.
    thanks again