/r/Unity2D

Photograph via snooOG

About


/r/Unity2D is a subreddit for news, tutorials, feedback, resources, and conversations related to 2D or 2.5D game development using the Unity game engine.

If the content is not related to 2D/2.5D development, it may belong in /r/Unity3D or /r/GameDev.


Official Discord

https://discord.gg/unity


Rules


Getting Started


Unity3D on GameDevWiki

Download Unity

Official Tutorials

Live Training Archive

Live Chat/Support - Game Dev League

Official Manual

Official Reference

Asset Store

Unity 2D forums

Tutorials Filter Wiki List

Software

Resources

Unity Web Demos

Related Communities

/unity3D on 8chan - Unity-focused image board

/r/UnityAssets - Share asset packs!

/r/PixelArt - Admire, share, and observe beautiful pixel art.

/r/GameDev - Meet and communicate with other game developers.

/r/GameDesign - Don't just make a game. Make a good game.

/r/LevelDesign - Learn to make excellent levels and worlds.

/r/GameAudio - It may look good, but does it sound good?


CSS created by Sean O'Dowd @nicetrysean [Website]

/r/Unity2D

146,738 Subscribers

1

Escape the swarm ! A sequence from Ether, our upcoming platforming game made with Unity.

1 Comment
2024/05/03
11:37 UTC

0

Hey guys Is there is any job in unity ?

I want to become unity game devloper and want to work with company

7 Comments
2024/05/03
09:58 UTC

0

Unlocking the Flavor Game: 5 Innovative Cooking Hacks for Unity2D Developers

As Unity2D developers, we are used to thinking outside the box. Why not apply that same creativity to the kitchen? Here are 5 game-changing cooking hacks that will level up your culinary skills and impress your taste buds. From using Unity's physics engine to perfectly cook a steak to creating pixel-perfect desserts, these hacks will take your cooking game to the next level. Get ready to code your way to a delicious meal in Unity2D!

1 Comment
2024/05/03
09:58 UTC

1

Rigidbody2d stopped working

I am making a 2d platformer game and using mlagents and for some reason rigidbody2d stopped working I thought maybe it is something with the script then I added a new game object and added rigidbody2d and still the same it just doesn't work for some reason

1 Comment
2024/05/03
08:18 UTC

1

Unity errors while pressing build and run on my Unity 2d game.

I was just gonna test my game if it works on mobile and i got errors.

Here are the errors i received:

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

FAILURE: Build failed with an exception.

The next one:

Starting a Gradle Daemon, 2 incompatible Daemons could not be reused, use --status for details

I'll be happy if anyone could help me with even one. I've wasted so much time trying to fix the errors. So please help.

0 Comments
2024/05/03
07:43 UTC

1

Im making an online game using mirror networking

Im pretty bad at using mirror and i was just wondering when i should do code like this or if i should do it like this

    void SpawnBullet()
    {
      //do bullet code
    }


    [Command]
    void serverSpawnBullet()
    {

        clientSpawnBullet();
    }


    [ClientRpc]
    void clientSpawnBullet()
    {
        SpawnBullet();
    }
    [Command]
    void serverSpawnBullet()
    {


        clientSpawnBullet();
    }



    [ClientRpc]
    void clientSpawnBullet()
    {
        SpawnBullet();
    }

if u have any tips PLZ lmk

2 Comments
2024/05/03
06:33 UTC

2

Can I easily change a UI image from code?

Hey all, I’m trying to make a simple choose-your-own-adventure game using the Ink scripting language. I’ve got things integrated and working except for one aspect: The images.

The game is based off of a comic I make and I want to feature images from the comic alongside the story. I’m in the early stages of planning, but I imagine 200-300 image files I would like to display over the course of the game.

Because this is text based, everything is UI elements on a canvas. The buttons and text are instantiated prefabs, but the image aspect is proving tricky. I can get the script to make an image, but I’m having trouble getting it to swap images.

In my perfect world, I’d be able to give a string of the image file name and then instantiate the matching file but this is proving tricky. My realistic goal is just to avoid creating 300 individual game objects on start.

Is there a way to change an image like this solely trhough text? Does anyone have any resources that would be helpful?

Thanks!

4 Comments
2024/05/03
05:23 UTC

24

This guy looks tough. Think you can beat him?

4 Comments
2024/05/02
20:24 UTC

1

Sliced Mask Creates Image Bleed

0 Comments
2024/05/02
15:41 UTC

1

Short legs … stylistic? Or practical?

I’m new to character design and game dev. I see many popular 2D games have characters with short legs (Cult of the Lamb, Oxygen Not Included, Don’t Starve, Castle Crashers, lots of pixel art).

Is this purely a stylistic choice? Or is there a reason for this like easier animation?

2 Comments
2024/05/02
15:25 UTC

2

Short legs … stylistic? Or practical?

I’m new to character design and game dev. I see many popular 2D games have characters with short legs (Cult of the Lamb, Oxygen Not Included, Don’t Starve, Castle Crashers, lots of pixel art).

Is this purely a stylistic choice? Or is there a reason for this like easier animation?

6 Comments
2024/05/02
15:25 UTC

1

Business Inquiry from Sona Sounds, KOREA

I am Jun-Young Choi, CEO at a Korean game sound studio Sona Sounds., and I would like to introduce ourselves to you for a possible business opportunity with your company.

Established in 2023, Sona Sounds specializes in the overall sound of games with several composers and engineers in our studio.

Currently, we are involved in the sound of several games in Korea and would like to discuss business opportunities with your game.

Please visit our studio website at https://sonasounds.studio for more information about our business and works.

We sincerely look forward to your favorable reply.

https://preview.redd.it/85pssgxm50yc1.jpg?width=3361&format=pjpg&auto=webp&s=bce8b3d6184ad61f288aa89965a9e09da1b2d413

https://preview.redd.it/vm10zp6n50yc1.jpg?width=2106&format=pjpg&auto=webp&s=e41a6e6b2669c4b645c8979b09713ad444771c46

0 Comments
2024/05/02
11:56 UTC

0

Help.

I was building my first unity game about automation and then this happened. This object won't delete "IronOre" tagged items but will detect them. I have no idea how this happened

https://preview.redd.it/um7b0fxlvzxc1.png?width=1488&format=png&auto=webp&s=5d09ba6e03c19becffb43c5d63ee8b53743bc19f

https://preview.redd.it/qu031ixlvzxc1.png?width=1432&format=png&auto=webp&s=3f8c7d99664bc9c0d124f57347546359500fa166

2 Comments
2024/05/02
10:59 UTC

6 Comments
2024/05/02
10:20 UTC

1

Main Menu and Game Playing at the Same Time?

I'm pretty brand new to game dev and programming and I've been trying to make my first Unity game - a flappy bird-like game, and I've been tearing my hair out a little trying to get my main menu working. Would really appreciate some help.

I have 2 scenes, a main menu scene and a game scene. Whenever I run the game I'm brought to my MainMenuScene, which works perfectly. If I quickly press play my "play game" button I'll be brought into the GameScene with no problems. However, if I don't press anything the "Game Over" UI from the GameScene will pop up over the main menu UI.

I'm assuming this is because GameScene is somehow playing, even when I'm in my MainMenuScene, so the bird dies and the Game Over UI pops up, but I don't know how to fix it. Can anybody help?

4 Comments
2024/05/02
07:46 UTC

2

Frame 0 Animation Event Problems

Hi all, I've basically run into a problem that can be summed up by: "StateMachineBehaviour method OnStateEnter fires before animation events on Frame 0."

I am not using blending, I have transition time = 0. Since some of the animation events I need to fire are audio-related, I need access to that Frame 0 for responsive audio, so I can't just push back the animation event to Frame 1.

Anyone know of solutions for this?

0 Comments
2024/05/02
06:50 UTC

1

Can you give me stores where I can upload phone games other than the Play Store and apple store

4 Comments
2024/05/02
03:37 UTC

0

knockback not working please help

(edit) i fixed the issue for the most part the ill add a frame of animation to it later:

thie issue was my else statement in my player controller.

/* else
        {
            if (knockFromRight)// Check if the player is being knocked back from the right
            {
                rb.velocity = new Vector2(-knockback, knockback);// Update the player's velocity
                if(!knockFromRight)// Check if the player is not being knocked back from the right
                {
                    rb.velocity = new Vector2(knockback, knockback);// Update the player's velocity
                    knockbackCount -= Time.deltaTime;// Update the knockbackCount


                }
            }
        }*/

here is my fix:

 else
        {   
        Vector2 knockbackDirection = knockFromRight ? Vector2.right : Vector2.left; // Determine knockback direction
        rb.velocity = knockbackDirection * knockback; // Apply knockback velocity
        knockbackCount -= Time.deltaTime; // Update the knockbackCount
         }
        

/*so i was trying to add a knockback to my player upon hit. however after being hit my player just walks away and after getting hit again keeps going until his hp hits 0 then when he respawns he keeps moving left and i cant control him.*/

sorry guys the coffee must have helped clear my head a bit lol.

i have a pastebin with comments for the code:

PlayerController.cs https://pastebin.com/g91EYXrC

DamagePlayer.cs https://pastebin.com/pNutdUvd

heres a video example of the error with my vocalizing the bug:

https://youtu.be/liUlbPJsp0E

player inspector with knockback knockback length, knockback count, and knock from right

6 Comments
2024/05/02
02:47 UTC

13

Thanks to everyone's help on the last few posts I've properly implemented parallax..(I hope). I also added some foreground elements to breakup the geometry of the map. What do we think??

6 Comments
2024/05/02
02:18 UTC

1

Help Exporting a 2D project (Sunny Land)

2 Comments
2024/05/02
01:21 UTC

1

Converting input texture2D to a 1x32x32x3 Tensor for input into an ONNX model in Unity

I have created a script in Unity that takes in a Texture2D and outputs a class prediction using an ONNX model that I have trained on the Cifar10 dataset. I have had success using a similar setup for the MNIST dataset so I think the issue is within converting the Texture2D to a Tensor as that is the only difference between the two scripts.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Unity.Barracuda;
using UI = UnityEngine.UI;
using TMPro;

public class Cifar10Script : MonoBehaviour
{
    public NNModel onnxAsset;
    public Texture2D imageToRecognise;
    public Texture2D tempImage;

    public UI.RawImage _imageView;
    public UI.Text _textView;

    public TMP_Text m_predictionTextDrawing;
    public TMP_Text m_predictionTextCamera;

    private int m_classPrediction;

    public void RunModel()
    {
        using Tensor input = new Tensor(1, 32,  32, 3);

        // Convert the input Texture2D into a 1x32x32x3 tensor.
        for (int y = 0; y < 32; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                int tx = x * tempImage.width / 32;
                int ty = y * tempImage.height / 32;
                input[0, 31 - y, x, 0] = tempImage.GetPixel(tx, ty).r;
                input[0, 31 - y, x, 1] = tempImage.GetPixel(tx, ty).g;
                input[0, 31 - y, x, 2] = tempImage.GetPixel(tx, ty).b;
            }
        }

        IWorker worker = ModelLoader.Load(onnxAsset).CreateWorker(WorkerFactory.Device.CPU);

        worker.Execute(input);

        Tensor output = worker.PeekOutput();

        float[] scores = Enumerable.Range(0, 10).Select(i => output[i]).ToArray();

        float[] outputBuffer = output.ToReadOnlyArray();

        float lowValue = -999;
        int index = -1;

        for(int i = 0; i < 10; i++)
        {
            print(i + " " + outputBuffer[i]);
            if (outputBuffer[i] > lowValue)
            {
                lowValue = outputBuffer[i];
                index = i;
            }
        }

        worker.Dispose();

        if (outputBuffer[index] < 0.6f)
        {
            //m_predictionTextDrawing.SetText("?");
            //m_predictionTextCamera.SetText("?");
            m_classPrediction = -1;
            //return -1;
        }
        else
        {
            m_classPrediction = index;
            //m_predictionTextDrawing.SetText(index.ToString());
            //m_predictionTextCamera.SetText(index.ToString());
        }
        m_classPrediction = index;
    }

    public int GetClassPrediction()
    {
        return m_classPrediction;
    }

}

The issue I am having is that the prediction scores remain very similar regardless of what image I pass it as a Texture2D. It seems to always have a 40% certainty that the image is one of a cat.

I have tried numerous trained models with different architectures, and I have tried switching out the images as well. I have tried constructing the Tensor by passing it a Texture as well which also did not work. I have narrowed down the issue to the point where I am fairly certain it is the converting from the Texture2D to a Tensor that is the issue.

1 Comment
2024/05/01
23:49 UTC

0

Light System of our hentai game, Please tell us how we could improve ! [Lustful Victor]

7 Comments
2024/05/01
22:23 UTC

0

Thanks for years without install fees

0 Comments
2024/05/01
21:30 UTC

1

How can I spawn GameObjects based on a variable? I need them to spawn on startup and on every variable change.

I'm starting with unity, and im trying to make a mobile game. I've made a system which works like this: Whenever player buys something, the integer value with name of the offer will increase. I need the GameObjects to spawn as many times, as is the current int value. Also i need them to be spawned whenever the game starts or the variable changes.

5 Comments
2024/05/01
20:31 UTC

0

Creating the game over panel and the you win panel

So I'm making a breakout game as part of 48 hours game jam with someone body else and i've been following a tutorial on how to build it. Now most of it works it is just that when to create a button that would restart the game, the on click section gives me nothing to select form.

Here the tutorial that i've been using it.

https://www.youtube.com/watch?v=jyXZ3RVe5as&list=PLKKdghJXq-BY5M5SPxIzlbLjMHsWL6YT8

This is the code on the ball script
public float minY = -5.5f;

public float maxVelocity = 15f;

Rigidbody2D rb;

int score = 0;

int lives = 5;

public TextMeshProUGUI scoreTex;

public GameObject[] livesImage;

public GameObject gameOverPanel;

public GameObject youWinPanel;

int brickCount;

// Start is called before the first frame update

void Start()

{

rb = GetComponent<Rigidbody2D>();

brickCount = FindObjectOfType<LevelGenerator>().transform.childCount;

rb.velocity = Vector2.down*10f;

}

// Update is called once per frame

void Update()

{

if(transform.position.y < minY)

{

if(lives <= 0)

{

GameOver();

}

else

{

transform.position = Vector3.zero;

rb.velocity = Vector2.down * 10f;

lives--;

livesImage[lives].SetActive(false);

}

}

if (rb.velocity.magnitude > maxVelocity)

{

rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxVelocity);

}

}

private void OnCollisionEnter2D(Collision2D collision)

{

if (collision.gameObject.CompareTag("Brick"))

{

Destroy(collision.gameObject);

score += 10;

scoreTex.text = score.ToString("00000");

brickCount--;

if (brickCount <= 0)

{

youWinPanel.SetActive(true);

Time.timeScale = 0;

}

}

}

void GameOver()

{

gameOverPanel.SetActive(true);

Time.timeScale = 0;

Destroy(gameObject);

}

}

and this is the script on the level generator

public Vector2Int size;

public Vector2 offset;

public GameObject brickPrefab;

public Gradient gradient;

private void Awake()

{

for (int i = 0; i < size.x; i++)

{

for (int j = 0; j < size.y; j++)

{

GameObject newBrick = Instantiate(brickPrefab, transform);

newBrick.transform.position = transform.position + new Vector3((float)((size.x-1)*.5f-i) * offset.x, j * offset.y, 0);

newBrick.GetComponent<SpriteRenderer>().color = gradient.Evaluate((float)j/(size.y - 1));

}

}

}

// Start is called before the first frame update

void Start()

{

}

// Update is called once per frame

void Update()

{

}

void Restart()

{

Time.timeScale = 1;

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

}

}

If i could get some help with this it would be greatly appreciated

0 Comments
2024/05/01
16:03 UTC

2

Drag drop swap ui elements

0 Comments
2024/05/01
15:55 UTC

Back To Top