Search Unity

Trying to draw outlines of a box using vertices

Discussion in 'Scripting' started by Drakegui, May 9, 2021.

  1. Drakegui

    Drakegui

    Joined:
    Jun 20, 2016
    Posts:
    2
    Hello! This is my first post here and I am probably in the wrong section to be asking this, but bear with me =)

    I'm currently developing a project game for university and its our first ever 2D game ( vertical slice ) being developed fully by ourselves.

    In our game, our player is required to draw the outlines of rectangles, connecting their vertices, to make a platform appear and to continue his path.

    We have a drawing mechanic using line renderers ( already working ) that creates a gameObject with each draw stroke.
    ss.png
    Being a complete beginner in unity, I have no idea what is my best approach here, given the fact that I cannot place colliders inside colliders to verify if the line went inside the rectangle, and I'm afraid for game optimization, given that just one platform in my example has 8 colliders, and the game revolves around these platforms.

    Would appreciate some thoughts here!
    Thank you ;D
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    Do you have a performance problem? If so, measure it with the profiler (Window -> Analysis -> Profiler). Any other approach to worrying about performance is likely wasted time.

    As far as your graphic "OnTriggerExit should destroy the drawing line game object", this may be practical, but you must first understand the implications of the physics system and when it is even possible for OnTrigger type calls to be called.

    OnTrigger style calls do NOT just happen "because" you sprinkle some stuff into your scene. They happen at a very specific point in the Unity engine lifecycle, and you can use them this way once you understand when they happen.

    Here is some timing diagram help:

    https://docs.unity3d.com/Manual/ExecutionOrder.html
     
  3. Drakegui

    Drakegui

    Joined:
    Jun 20, 2016
    Posts:
    2
    Thank you for the reply!

    At the moment I do not have any performance issues as the game's prototype is barely done, I was thinking about long term, having so many colliders in only one object that is used multiple times across the game... but I'm starting to think to not worry too much about it now, as I am just developing a vertical slice of the game and therefore should not have such a big impact in performance in the final product.