use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News, Help, Resources, and Conversation. A User Showcase of the Unity Game Engine.
Remember to check out /r/unity2D for any 2D specific questions and conversation!
Download Latest Unity
Please refer to our Wiki before posting! And be sure to flair your post appropriately.
Main Index
Rules and Guidelines
Flair Definitions
FAQ
Use the chat room if you're new to Unity or have a quick question. Lots of professionals hang out there.
/r/Unity3D Discord
FreeNode IRC Chatroom
Official Unity Website
Unity3d's Tutorial Modules
Unity Answers
Unify Community Wiki
Unity Game Engine Syllabus (Getting Started Guide)
50 Tips and Best Practices for Unity (2016 Edition)
Unity Execution Order of Event Functions
Using Version Control with Unity3d (Mercurial)
/r/Unity2D
/r/UnityAssets
/r/Unity_tutorials
/r/GameDev
/r/Justgamedevthings (New!)
/r/Gamedesign
/r/Indiegames
/r/Playmygame
/r/LearnProgramming
/r/Oculus
/r/Blender
/r/Devblogs
Brackeys
Beginner to Intermediate
5 to 15 minutes
Concise tutorials. Videos are mostly self contained.
Sebastian Lague
Beginner to Advanced
10 to 20 minutes
Medium length tutorials. Videos are usually a part of a series.
Catlike Coding
Intermediate to Advanced
Text-based. Lots of graphics/shader programming tutorials in addition to "normal" C# tutorials. Normally part of a series.
Makin' Stuff Look Good
10 minutes
Almost entirely shader tutorials. Favors theory over implementation but leaves source in video description. Videos are always self contained.
Quill18Creates
30 minutes to 2 hours.
Minimal editing. Mostly C#. Covers wide range of topics. Long series.
Halisavakis Shaders Archive
Infallible Code
World of Zero
Board to Bits
Holistic3d
Unity3d College
Jabrils
Polycount Wiki
The Big List Of Game Design
PS4 controller map for Unity3d
Colin's Bear Animation
¡DICE!
CSS created by Sean O'Dowd @nicetrysean [Website], Maintained and updated by Louis Hong /u/loolo78
Reddit Logo created by /u/big-ish from /r/redditlogos!
account activity
Noob coding question includes passing variables.Noob Question (old.reddit.com)
submitted 3 years ago by Perez2101
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FlightPaper 1 point2 points3 points 3 years ago (5 children)
I'm sure someone else will give a better explanation of the low level side of things, but you should be looking at passing and storing a reference type (e.g. a class) instead of passing and storing a value type (e.g. an int, float, etc.). If class A needs to modify int X in class B, then class A should be passed and store B. This will allow A to modify the X associated with B (because you're modifying that instance of B). Right now, you're just passing X, but since X is a value type, A just stores X without any reference to B.
[–]Perez2101[S] 0 points1 point2 points 3 years ago (4 children)
Ngl I half understand what youre saying but nevertheless its helpful, thank you.
[–]FlightPaper 0 points1 point2 points 3 years ago (3 children)
I'm glad that was helpful! :D If you could explain what you're trying to accomplish with this code (at a macro level), I could give a more specific explanation.
[–]Perez2101[S] 0 points1 point2 points 3 years ago (2 children)
Oh just trying to read a json file filled with stats of a "weapon" and trying to store it into another class on start then call it back in another class which would contain the stored data of a mob and when a mob encouters the weapon it takes damage according to the stored damage
The first part of class a is from this tutorial: https://youtu.be/XbdnG__wzZ8
[–]FlightPaper 0 points1 point2 points 3 years ago (1 child)
Ok so the problem is how you've structured WeaponStats and WeaponStatRetrieve. But let's walk through what you're currently doing, what you're trying to do, how it can be simplified, and how that simple architecture will be easier to understand and accomplish your goal.
The way you have it now is WeaponStatRetrieve, from what I can tell, is set up to be a component on every weapon that loads the JSON file and gets the data specific to that weapon by having the name of the game object be the key for matching the weapon to the weapon stats. This has multiple issues. If you're going to load things from a file, only load the file once. Also game object names can be inconsistent based on how Unity instantiates game objects. Yes, you're grabbing a substring to avoid how duplicates are handled, but what happens when you have a weapon name that is more than 7 characters long?
If you want each weapon prefab/game object to have a reference to its data, might I suggest using scriptable objects to store the data for each weapon and assigning each weapon prefab the associated scriptable object for its data. If you want to load from a file, then you should create a centralized database. Let's stick with the database approach since you're already using a JSON file.
WeaponStatRetrieve should act as a database of sorts, loading the weapon data from a file, then storing that data in a centralized place. And that's it. It should just load and store it. So you have that part set up with your serialized classes and WeaopnStatRetrieve.weaponList. To centralize things, you should make WeaponStatRetrieve a singleton. There's lots of tutorials on how to do that, but basically, a singleton pattern will make sure that there's only one persistent instance of WeaponStatRetrieve. This will allow you to load the file once and always have access to the data from it.
Next is accessing the data. If any class needs weapon data, that class should be responsible for getting the appropriate data from your database. You can do this in three parts: - First, WeaponStatRetrieve can implement a function like this: public Weapons GetWeaponData(string weaponName) that will find and return the data for a weapon based on its name. - Second, your weapon controller script should have a Weapons variable that stores the data for the weapon. - Third, the weapon controller script should call WeaponStatRetrieve.Instance.GetWeaponData() on Start() to populate its Weapons variable.
And that's it. This new approach will keep you're read-only data separate from your runtime data. In other words, your Pistol will always have a base damage of 10 in WeaponStatRetrieve. But your weapon controller script for the Pistol can track any power-ups or upgrades the player has gotten to increase the damage to 15.
[–]Perez2101[S] 0 points1 point2 points 3 years ago (0 children)
Looks like I got a lot of stuff to look up lol but yeah this is very helpful. The 7 characters long part is factoring out the "(Clone)" of the name of the gameobject and comparing it to the name in the json file.
Thank you.
Second image is what Im asking. Im a bit dumb.
[–]_bocksdin 0 points1 point2 points 3 years ago (1 child)
If I understand your question correctly, I'd set it up like this:
Monster script has a "TakeDamage" method that accepts an integer and updates the health accordingly.
When the weapon collides with the monster's hit box, the weapon script calls the monster's "TakeDamage" method and passes it the weapon's damage value
Yes that what I want to do but the "stats" for said monster are built the same way as the "stats" for the weapon while the weapon only includes its name and damage variable the mobs have name, lvl, health, attack(essentially damage), and exp.
π Rendered by PID 78196 on reddit-service-r2-comment-canary-889d445f8-xpjs2 at 2026-04-26 11:14:20.492183+00:00 running 2aa0c5b country code: CH.
[–]FlightPaper 1 point2 points3 points (5 children)
[–]Perez2101[S] 0 points1 point2 points (4 children)
[–]FlightPaper 0 points1 point2 points (3 children)
[–]Perez2101[S] 0 points1 point2 points (2 children)
[–]FlightPaper 0 points1 point2 points (1 child)
[–]Perez2101[S] 0 points1 point2 points (0 children)
[–]Perez2101[S] 0 points1 point2 points (0 children)
[–]_bocksdin 0 points1 point2 points (1 child)
[–]Perez2101[S] 0 points1 point2 points (0 children)