/r/Unity2D
/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.
Live Chat/Support - Game Dev League
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
I want to become unity game devloper and want to work with company
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!
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
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.
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
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!
Every time I use a sliced mask in Unity, it bleeds out in the edges. The name/age label is a 9-sliced Image component with a child that's the stripe pattern. It masks the stripe pattern, but you can see a bit spilling out in the corners. I have this a LOT in my UI so it's really an eyesore:
Settings:
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?
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?
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.
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
i can detect the tag but not the object??
pls send help
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?
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?
(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:
player inspector with knockback knockback length, knockback count, and knock from right
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.
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.
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