unity – How to create a aimLine in a pool game on unity2d?

I want to design a Aim Line for my player in unity2d. The game is split screen so what I basically want is that whenever its my player turn I want my player which is a ball to cast a raycast like you see in pool/snooker/billiard games. Reference.

This image is what I want. I have done some research and this image is also from other forum which uses Gl lines that seems a little complicated for me So what I have done is this.

   public LineRenderer lr;
public Transform rayStart;
void FixedUpdate()
{
    // Cast a ray straight down.
    RaycastHit2D hit = Physics2D.Raycast(rayStart.position, Vector2.up);

    // If it hits something...
    if (hit)
    {
        Debug.Log(hit.transform.name);
        lr.SetPosition(0, rayStart.position);
        lr.SetPosition(1, hit.point);
   
    }
}

UPDATE

so Now what I am trying to do is that I am not touching my player which I did using this thread. Now I have added a game Object behind my player that will shoot a raycast which works like a cue. I dont know which way to go but current code on that object is

`

public LineRenderer lr;

private void Start()
{
     
}
void Update()
{
    // Cast a ray straight down.
    RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.up);

    if (hit)
    {

        lr.SetPosition(0, transform.position);
        lr.SetPosition(1, hit.point);
    }
   
    
}`

unity – Unity2D: Character goes up and down during idle animation

My character is idling but his feet are changing position during the animation: it seems he’s floating. I would like to have the character with his feet stuck.

Video to visualize the issue: https://vimeo.com/568057364

As you can see, the feet are going up and down. I’ve also tried to animate the collider in order to follow the feet, but that attempt didn’t solve the issue.

unity2d – Creación de Inventario c#

Hola estoy tratando de hacer un inventario 2D siguiendo un video, pero me da este error al tratar de spawnear los objetos por el mundo. Creo que tengo el codigo igual que en el video pero quizas hay algo que no estoy viendo.

El error es al saltar de un script a otro (Object reference not set to an instance of an object, ):
Me da el error en la función awake de la segunda imagen

Este seria el script del que cojo la información

Y este el que me da el problema en la función Awake

unity2d – Después de reiniciar el PC, Unity no abre los proyectos

Creo los proyectos, se abren después de crearlos, trabajo en ellos, los guardo, cierro el proyecto y después de reiniciar el PC ya no se abren.

Cuando intento abrir estos proyecto después de haber reiniciado parece que Unity Editor intenta abrirlos porqué sale el recuadro de fondo inicio con el nombre de Unity pero no abre nada. El programa Unity Hub sigue funcionando y puedo crear nuevos proyectos y abrirlos con el Unity Editor, pero los otros proyectos no.

Me ocurre con ambas versiones que he probado, Unity LTS de 2019 y Unity de 2020 ultima versión (pero no la más nueva de prueba alfa y beta).

unity – Selection Cursor with OnMouseEnter or OnMouseHover Unity2D?

I want to be able to have a selection arrow appear next to the sprite that the player has their mouse over and disappear when MouseExits but I can’t seem to figure out how to make this work. I don’t have any code to start with because I have no idea how to start it (sorry!) Does anyone know any code or Unity process that has this work?

Example: OnMouseOver, yellow selection sprite appears at the origin (0,0) of the Noodles sprite

I’m kinda still a beginner when it comes to Unity so any and all help is welcome! Also sorry if the question has already been answered, I googled for an answer and didn’t find one after 3 Google Pages.

unity – How to fuse 2 sprites as they approach each other in Unity2D?

Thanks for contributing an answer to Game Development Stack Exchange!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

To learn more, see our tips on writing great answers.

unity – (Unity2D) Help – Some things not working on build

it’s my first time building a project to try it out and i’m facing some problems.

The game is a simple brickbreaker clone that is currently working fine while in the editor.

The problems starts when i build the game.
The things that are not working are the block that are not showing up at all. Those are instantiated everytime a new level is being built.
And also, the “OffsideZone” where the balls collides and disappear so the player loses one life is not working, the ball disappears but nothing happens, it’s like the scripts are not running or something.
The ball is also instantiated at the beginning of the game and it’s working fine.

I’m not sure what’s going on.

Editor

unity – How do I dynamically use the rect tool in Unity2D?

The rect tool in Unity2D (I honestly do not remember if it is present in Unity3D) allows you to scale down/scale up an object in just one direction (what it does is it simultaneously increases/decreases the height of an object in transform.scale and transform.position. I was trying to scale down an object while keeping its position the same using this code (P.S. I took the first four lines of code from here: The Best Way To Generate a Random Float in C#):

       float range = (double)float.MaxValue - (double)float.MinValue;
       float sample = scaleRand.NextDouble();
       float scaled = (sample * range) + float.MinValue;
       float f = (float)scaled;
        if (f > 0.6f)
        {
            f = 0.6f;
        }
            gameObject.localScale = new Vector2(gameObject.lossyScale.x, (gameObject.lossyScale.y - f));

However, this code does not work. So, how can I recreate the effect of using the rect tool in Unity Editor using C#?

unit – Unity2D: How to check the job system for overlaps

Currently I have implemented a job in Unity for performance reasons. In this job, I check whether a game object overlaps with the "detection circle". The job looks like this:

(BurstCompile)
public struct CreateGridJob : IJob
{
    public float diameter, radius;
    public NativeArray positionsArray;
    public NativeArray isWallArray;
    public float3 bottomLeft;
    public int sizeX, sizeY;
    public float3 right, up;
    public LayerMask layer;

    public void Execute()
    {
        int x = 0, y = 0;
        for (int i = 0; i < positionsArray.Length; i++)
        {
            float3 point = bottomLeft + right * (x * diameter + radius) + up * (y * diameter + radius);
            bool wall = true;
            Vector3 worldPoint = point;
            if (Physics2D.OverlapCircle(worldPoint, radius, layer))
                wall = false;
            positionsArray(i) = new int2(x, y);
            isWallArray(i) = wall;


            if (x % sizeX == 0)
                x++;

            y++;
            if (y >= sizeY)
                y = 0;
        }
    }
}

The problem course when I have to call if (Physics2D.OverlapCircle(worldPoint, radius, layer))since it can only be called in the main thread and therefore throws an exception.

The result of this job is a grid that is used in path finding.

Am I going in the right direction or is there another way to do this?

Edit-1: Unfortunately no, not all are convex (can be changed if there is no other way).

Here is an example of a concave asteroid:

Enter the image description here

There are many of these asteroids scattered across the scene. First, they are grouped into sectors, and each sector has its own asteroids. Sectors are independent of each other and only connected via portals. For the simulation, all (at least for now) sectors are active and generate their grid. However, a single sector can have, for example, 200 asteroids. They are placed at random.