r/Unity3D – Telegram
r/Unity3D
266 subscribers
12.7K photos
15.6K videos
14 files
48K links
News about the Unity engine and project showcases from Reddit. Made possible with @reddit2telegram (@r_channels).
Download Telegram
Media is too big
VIEW IN TELEGRAM
I’ve always dreamed of creating a paradise, and as soon as I learned Unity, I set out to make Vacation Cafe Simulator, a cozy game. Experience the charming streets of Italy, sip on Prosecco, and craft incredible culinary masterpieces in your very own café.

https://redd.it/1gsipgl
@r_Unity3D
The hand doesn't stick to the spring, help

I have troubles with making this hand stick to the bottom of the spring when i change size in "tiled" draw mode

https://preview.redd.it/zmaxhv93r81e1.png?width=2375&format=png&auto=webp&s=3803cc48df0d050b4288816e874531daa33632f9

https://preview.redd.it/dxkqzdy3r81e1.png?width=2359&format=png&auto=webp&s=541e95fa563f898afbb617105235520d3d05884e

I've tried to do it with

claw.transform.position = new Vector3(claw.transform.position.x, spring.transform.position.y, 0);

but it doesn't respond to changes.

https://redd.it/1gskmob
@r_Unity3D
Refering to a UI gameObject when prefab is instantiated

So the big sqaure in the middle with the image and the text that says \\"Tower, Stage 1, Firerate: 1, Upgrade\\" is the box i want to make appear.


So i im currently working on a small project, where its a Tower Defense game, and you earn your money by a little clicker minigame. I made the whole thing work fine, and you can buy towers and that. BUT now i want to basicly open up an upgrade menu where you can upgrade your towers. This is my current code for my tower:

using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

using UnityEngine.UI;

public class CastleTower : MonoBehaviour

{

public TowerController towerController;

public SpriteRenderer SpriteRenderer;

public Sprite Castle1;

public Sprite Castle2;

public Sprite Castle3;

public Sprite Castle4;

public Sprite Castle5;

public bool Castle1Shown;

public bool Castle2Shown;

public bool Castle3Shown;

public bool Castle4Shown;

public bool Castle5Shown;

private bool isTakingDamage = false;

public int health;

private GameObject currentEnemy = null;

public Sprite currentSprite;

public Image upgradeImage;

public UpgradeMenu upgradeMenu;

public Ghost ghost;

private void Awake()

{

upgradeMenu = GameObject.Find("Upgrade Menu").GetComponent<UpgradeMenu>();

}

// Start is called before the first frame update

void Start()

{

currentSprite = Castle1;

upgradeMenu.closeMenu();

Castle1Shown = true;

Castle2Shown = false;

Castle3Shown = false;

Castle4Shown = false;

Castle5Shown = false;

}

// Update is called once per frame

void Update()

{

if (ghost.towerPlaced == true)

{

upgradeMenu = GameObject.Find("Upgrade Menu").GetComponent<UpgradeMenu>();

}

upgradeImage.sprite = currentSprite;

if (health < 0)

{

Destroy(gameObject);

}

if (Castle5Shown == true)

{

this.gameObject.GetComponent<SpriteRenderer>().sprite = Castle5;

Castle1Shown = false;

Castle2Shown = false;

Castle3Shown = false;

Castle4Shown = false;

currentSprite = Castle5;

}

if (Castle4Shown == true)

{

this.gameObject.GetComponent<SpriteRenderer>().sprite = Castle4;

Castle1Shown = false;

Castle2Shown = false;

Castle3Shown = false;

Castle5Shown = false;

currentSprite = Castle4;

}

if (Castle3Shown == true)

{

this.gameObject.GetComponent<SpriteRenderer>().sprite = Castle3;

Castle1Shown = false;

Castle2Shown = false;

Castle4Shown = false;

Castle5Shown = false;

currentSprite = Castle3;

}

if (Castle2Shown == true)

{

this.gameObject.GetComponent<SpriteRenderer>().sprite = Castle2;

Castle1Shown = false;

Castle3Shown = false;

Castle4Shown = false;

Castle5Shown = false;

currentSprite = Castle2;

}

if (Castle1Shown == true)

{

this.gameObject.GetComponent<SpriteRenderer>().sprite = Castle1;

Castle2Shown = false;

Castle3Shown = false;

Castle4Shown = false;

Castle5Shown = false;

currentSprite = Castle1;

}

}

public void OnMouseDown()

{

upgradeMenu.openMenu();

}

private void OnTriggerEnter2D(Collider2D collision)

{

if (collision.gameObject.CompareTag("Enemy") && !isTakingDamage)

{

Debug.Log("Enemy collided with: " + gameObject.name);

currentEnemy = collision.gameObject; // Store the enemy reference

StartCoroutine(TakeDamageOverTime());

}

}

private void OnTriggerExit2D(Collider2D collision)

{

if (collision.gameObject == currentEnemy)

{

StopCoroutine(TakeDamageOverTime());

isTakingDamage = false;

currentEnemy = null; // Clear the enemy reference

}

}

private IEnumerator TakeDamageOverTime()

{

isTakingDamage = true; // Mark that damage is being applied

while (currentEnemy != null) // Ensure the enemy still exists

{

health -= 1; // Reduce health by 1

yield return new WaitForSeconds(1f); // Wait for 1 second

}

isTakingDamage = false; // Stop damage when the enemy is destroyed

}

public void stage1Active()

{

Castle1Shown = true;

}

}

And this is my code for spawning in the tower:

using
System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Ghost : MonoBehaviour

{

public GameObject CastleTower1;

// Define the placement bounds (adjust these values to fit your specific area)

public Vector2 minBounds = new Vector2(-5.5f, -4.4f); // Bottom-left corner

public Vector2 maxBounds = new Vector2(5.5f, 4.5f); // Top-right corner

public CastleTower castleTower;

public bool towerPlaced;

private void Start()

{

towerPlaced = false;

}

// Update is called once per frame

void Update()

{

// Get the mouse position in world space

Vector3 mousPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

mousPos.z = 0;

// Clamp the position to stay within the defined bounds

mousPos.x = Mathf.Clamp(mousPos.x, minBounds.x, maxBounds.x);

mousPos.y = Mathf.Clamp(mousPos.y, minBounds.y, maxBounds.y);

// Update the ghost's position

transform.position = mousPos;

// Place the tower and destroy the ghost on left mouse click

if (Input.GetMouseButtonDown(0))

{

// Check if the position is within the allowed area (optional, as clamping already handles this)

if (IsWithinBounds(mousPos))

{

Instantiate(CastleTower1, transform.position, Quaternion.identity);

Destroy(gameObject);

towerPlaced = true;

}

}

}

bool IsWithinBounds(Vector3 position)

{

return position.x >= minBounds.x && position.x <= maxBounds.x &&

position.y >= minBounds.y && position.y <= maxBounds.y;

}

}It is probably really messy, but this is one of my first games, so bare over with me. When the tower is in the scene as i start, it ofc works fine, and the refence works too. But when i go ahead and instantiate one, the refence dosent go through. I've thought about it alot, but can't seem to figure out how to do it.

Does anyone know how to do this?

https://redd.it/1gslz4p
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
It took us three years, but now everything is destructible in our upcoming game.
https://redd.it/1gsndkz
@r_Unity3D
Looking for advice on where to start to create a "level maker" feature where players can make, export, and share 2D maps

I want to make a game where people can make and share levels, but I want the editor to be very automated and controlled so that players don't have to worry about things like explicitly setting lighting effects, collisions, interactive objects, etc, that they can just grab and drop tiles or objects into the editor and logic handles how the game world effects it.

https://redd.it/1gsovpg
@r_Unity3D
I hate this part. (Camera explanation and mini rant in the comments.)
https://redd.it/1gsqxg3
@r_Unity3D
Sliding panel doesn't work

I'm tring to make the panel slide when i click the button, and when i click the mouse (end of the action). the first time works, but after that it just stops working. why?

Here is my code:

    IEnumerator Slide() {
        Vector3 temp;

        if(!hidden) {
            temp = panel.transform.position + new Vector3(0, -150);
        } else {
            temp = panel.transform.position + new Vector3(0, 150);
        }

        hidden = !hidden;

        while((panel.position - temp).sqrMagnitude > Mathf.Epsilon) {
            panel.position = Vector3.MoveTowards(panel.position, temp, 400 * Time.deltaTime);
            yield return null;
        }

        panel.transform.position = temp;
    }

https://i.redd.it/f0o3ki46ka1e1.gif



https://redd.it/1gsr3ur
@r_Unity3D
Issue with Inspector/Hierarchy

Hi, so I'm pretty new to unity and its suuuper frustrating. I'd be very happy if someone could help.

I have an object that is called "Vessel" and a Script that controls interactions with said object. I need to assign the object to the Player Interaction Script so that the noscript knows which object in the scene I want the player to be able to interact with.
But when I try to drag and drop the object from the hiearchy into the Inspector of the noscript, it doesnt work. Neither does searching for it on the button next to None (Game Object).


Here's the noscript:
using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class InteractionScript : MonoBehaviour

{

[SerializeField\] private Transform player;

[SerializeField\] private GameObject[\] interactableObjects = new GameObject[3\];

[SerializeField\] private float interactionRange = 3f;

[SerializeField\] private Animator animator;

[SerializeField\] private GameObject vesselObject;



private int objectsFound = 0;

private bool allObjectsCollected = false;



void Update()

{

if (Input.GetMouseButtonDown(1))

{

foreach (GameObject obj in interactableObjects)

{

float distance = Vector2.Distance(player.position, obj.transform.position);



if (distance <= interactionRange && obj.activeSelf)

{

TriggerInteraction(obj);

break;

}

}



if (allObjectsCollected && Vector2.Distance(player.position, vesselObject.transform.position) < interactionRange)

{

TriggerVesselInteraction();

}

}

}



private void TriggerInteraction(GameObject obj)

{

animator.SetTrigger("Inspect");

obj.SetActive(false);

objectsFound++;



if (objectsFound == interactableObjects.Length)

{

allObjectsCollected = true;

Debug.Log("Alle Objekte gefunden! Du kannst jetzt mit dem Vessel interagieren.");

}



TextManager.Instance.UpdateProgress();

}

}

funny thing is, it worked just fine before I worked on something else and tried to undo the other actions, but somehow the ctrl+Z just deselected everything in all of my Inspectors. I just don't get Unity.



https://redd.it/1gsu9ms
@r_Unity3D
I'm a beginner at 2d game developeing and i want to learn from some group projects. Anyone interested?



https://redd.it/1gsuv63
@r_Unity3D
GUIDs are amazing, especially when saving objects.

I just started making a saving system for my game, and using GUIDs for all of my objects makes everything so easy. It especially makes saving noscriptable objects easier. All I do is, generate a GUID for all of my noscriptable objects in the noscriptabe objects inspector, and when I load the game, I load all the noscriptable objects using Resources.LoadAll and add them to a dictionary with their GUIDs, and Instantiate the ones that were saved by finding their IDs from the dictionary, and then setup all of the instantiated objects with their saved GUIDs as well. I don't know if there is a better way of doing this, but this works fine for me. I use GUIDs for my shop system and inventory system as well, it makes everything so easy so I started using them for most of my systems. Do you use GUIDs in your games?

https://redd.it/1gstg4v
@r_Unity3D
Media is too big
VIEW IN TELEGRAM
Now imagine you're building something like that in a hack-and-slash game like Hades! Do you think it feels enough like a power fantasy, or is it too generic? It’s a bit hard to understand at first, but it’s not too difficult if you pay attention. And yes, I added these subnoscripts just for you :D

https://redd.it/1gnoscriptjc
@r_Unity3D
Building for IOS

Hi, for building for IOS i’ve heard that you need a Mac to build it on alongside a developers license. Is it possible to build via github actions or another alternative since apple hardware is usually not cheap. Any suggestions?

https://redd.it/1gt26g4
@r_Unity3D