HOW TO ACCESS DATA FROM ANOTHER SCRIPT 🎮 | Get Data From Other Scripts In Unity | Unity Tutorial

  Рет қаралды 108,022

Dani Krossing

Dani Krossing

2 жыл бұрын

Hi everyone! 🙂 Today I will show how to access data from another script in Unity. This is something a lot of people don't know when just starting out in Unity, so I figured a video would be helpful to some.
Learn C# here: • 1: Introduction To C# ...
Download Unity here: unity3d.com/get-unity/download
➤ GET ACCESS TO MY LESSON MATERIAL HERE!
First of all, thank you for all the support you have given me!
I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
I am now using Patreon and KZfaq Memberships to share improved and updated lesson material, and for a small fee you can access all the material either from my memberships or Patreon, depending on your preference. I have worked hard, and done my best to help you understand what I teach.
I hope you will find it helpful :)
Memberships: / @dani_krossing
Patreon: / mmtuts

Пікірлер: 202
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
Like one of my viewers pointed out, I accidentally switched around the awake() and start() in regards to where you need reference other components. 😬 You need to assign properties in awake(), and components in start(). Also, if you want to access static properties or methods then you don't need to do it in this way. 🙂 A static property or method can always just get accessed without needing to reference the class first at the top, since it's static. Like I mentioned, my PlayerController was roughly put together, so yes my "disabled" property would have been better off as static.
@kabhikachambala3392
@kabhikachambala3392 2 жыл бұрын
#Dan please I beg you to teach us how to update database using php step by step . In your tutorial you showed how to update database from inside mysqli. I'm getting trouble in this issue. I've tried a lot but no successful and I don't find the mistake.
@zandorkie8743
@zandorkie8743 2 жыл бұрын
I know this is an old video but is it possible to do this with multiple objects?
@DensetsuVII
@DensetsuVII 2 жыл бұрын
Dani I spent at least 10 hours moving across at least 10 tutorials on how to do this and NOTHING worked except you. As someone just getting started, I have this feeling that your video may honestly have made the difference between me giving up on the entire sordid affair and having the hope to feel like I can persist. I really can't express how thankful I am to have found this - subscribed, liked, everything I can do to say thank you. Keep it up!
@tramarthomas6105
@tramarthomas6105 2 жыл бұрын
I'm not a pro at programming, but C# and game development have me feeling like a newbie again. These tutorials are great
@NotTheHeroStudios
@NotTheHeroStudios Жыл бұрын
Tbh Dani is one of the few people I just click with, I've delt with a lot of guides while learning, paid and free, and I always come back here. He just has a relatable vibe and he explains things like we don't know (because we probably don't) BUT isn't condescending about it. It's like hearing a friend explain something and I think that's why it's so good. Info is on point, it's explained in an easy to follow, not slow and not too fast way, and he's super informative while being entertaining, he's basically what I wanted from Brackley's channel. And I'm not saying Brackley's is bad, but it's more pieces of education, while Dani is more of a full start to finish course. You get the paid type of education that's not tedious to follow while being accessible to anyone with an internet connection. Truely one of best unity teachers out there IMO
@cassiantrip996
@cassiantrip996 2 жыл бұрын
THANK YOU!!!! It took me a while and a LOT of cross-referencing to figure this out, and I still wasn't sure if my approach was "right". It's nice to have the confirmation for peace-of-mind. I wish I could have just seen this from the start. I'd recommend this video to anyone starting out in Unity scripting who's looking to lay some foundations for themselves.
@sticraft41
@sticraft41 2 жыл бұрын
I have spent hours trying to understand how to do this basic thing. Your video cleared it all out for me, and even more, thank you
@samshadessss
@samshadessss 2 жыл бұрын
bro, first time watching a video of yours and i got to say, you appear very friendly and you explain very well. i just wish i had seen this video a couple years back. keep up the great work.
@VinciWare
@VinciWare Жыл бұрын
This is actually a great tutorial! Saved to my playlist for future reference and I subscribed to your channel. Cheers dude!
@russelllapua4904
@russelllapua4904 2 жыл бұрын
You've always been good at explaining stuff. Between you and netninja everything i need is covered.
@tarekmustafa2525
@tarekmustafa2525 Жыл бұрын
I was looking for this info all over the place. Thank you for this great Tutorial!
@spurgis6280
@spurgis6280 2 жыл бұрын
I was looking for this for so long and finaly found it!!! THANK YOU SO MUCH
@Giucalistro
@Giucalistro 2 жыл бұрын
I'm just starting out on unity and this was incredibly useful, thank you!
@MrMercerMvs
@MrMercerMvs Жыл бұрын
Thankyou for this tutorial. I was stuck in my code for like 4-5 hrs. This is the only tutorial that solved my problem❤❤❤
@Bella-ey5wb
@Bella-ey5wb Жыл бұрын
you explain stuff so clearly! this was great help
@ryker4688
@ryker4688 2 жыл бұрын
This helped loads. Thanks. I was having trouble setting up an upgrade system and item collector as I needed to swap data between them. Cheers.
@jan6335
@jan6335 2 жыл бұрын
same here :,)
@GermanVargas
@GermanVargas Жыл бұрын
Great tutorial! Very descriptive and easy to follow. Great work!
@Synthali
@Synthali Жыл бұрын
Okay, how do I like a video more than once? This was amazing! Every old forum post I went to had some sarcastic smartass with an answer that didn't work, but this is perfect! Thank you!
@user-ib6sy1cd2u
@user-ib6sy1cd2u Жыл бұрын
You're the best of the best. I tried to fix my code for 4 hours, but after watching your video, I fixed that by a second. Thank you a lot!!!!
@bryleerowe6089
@bryleerowe6089 5 ай бұрын
Thank you so much!!!!! I had spent countless hours trying to get this to work and finally I got it to work!!!!
@tPlayerioT
@tPlayerioT Жыл бұрын
i was taking 30min to find whatever was happening and finally this vidoe helped out lol. its good to know that i have to reference a object to the script.
@trueblue97
@trueblue97 2 жыл бұрын
Where were these videos when I first started? Very well thought out stuff, nice work!
@AcidDotCom
@AcidDotCom Жыл бұрын
What a legend! Thanks for saving me hours if not days of figuring it out :)
@WhatsTheMeaningofMySuffering
@WhatsTheMeaningofMySuffering 2 жыл бұрын
Just randomly found this video and my mouse went subscribe in 2 minute mark cuz of the way of your manner of telling how its done. Thank you.
@maaz4354
@maaz4354 2 жыл бұрын
Thank you so much! I got stuck on this for far too long :)
@here_krsna
@here_krsna 2 жыл бұрын
Cool! You helped me a lot bro! Keep up good work 👍👍
@JG-Games97
@JG-Games97 Жыл бұрын
Thank you, this helped a lot. I've been struggling on how to do this for two days for my college project.
@thismakesnosense
@thismakesnosense Жыл бұрын
Thanks for the simple explanation!
@ForIEqualsZero
@ForIEqualsZero 2 жыл бұрын
i love your vids!!!! they are the best out there
@Bogi494
@Bogi494 Жыл бұрын
Thank you so much I really needed this tutorial! You earned a sub.
@triminh5699
@triminh5699 Жыл бұрын
The video was so helpful!Thanks a lot!
@storm4605
@storm4605 2 жыл бұрын
dude, you are the best explainer ever. i understood everything. thank you so much.
@rovicpenaloza3120
@rovicpenaloza3120 2 жыл бұрын
Damn! Worked like a charm! Thank you soooo much!
@VapeStation5
@VapeStation5 Жыл бұрын
Very good, quick, and complete video!
@ThePilgrums
@ThePilgrums Жыл бұрын
this really helped me out! thanks!!
@med8308
@med8308 Жыл бұрын
thank u so much man. This really helped.
@hanifkukuhraharjo4545
@hanifkukuhraharjo4545 2 жыл бұрын
Great turtorial! Love it!
@argentumstaar
@argentumstaar 2 жыл бұрын
Thank you, Sir! This video is a gift.
@shubhamkumarsinha4013
@shubhamkumarsinha4013 2 жыл бұрын
This is exactly what I was looking for. 'Thank U'
@ads4752
@ads4752 Жыл бұрын
Thank you, this video helped me figure out an ammo script for my game.🙏
@tzuchingwen9986
@tzuchingwen9986 2 жыл бұрын
Exactly what i struggling with, thank you!!!
@paulvladislav4280
@paulvladislav4280 2 жыл бұрын
Good straight forward tutorial. Cheers!
@fulgencejuniorlohore854
@fulgencejuniorlohore854 12 күн бұрын
Thanks buddy for this useful tutorial!
@zxbbvnm
@zxbbvnm Жыл бұрын
Thank you Dani!!
@tonybear12
@tonybear12 Жыл бұрын
THANK YOU SO MUCH!!!!!!!! YOU SAVED MY LIFE YOU'RE AN ABSOLUTE GOD
@TheARTofMining
@TheARTofMining 2 жыл бұрын
Very clear . Thank you !!
@l.g5390
@l.g5390 Жыл бұрын
Best tutorial helped me a lot 🎉
@berat02xz
@berat02xz 2 жыл бұрын
I dont use any game engine, but i still watch your unity videos because they really do help with other aspects outside of game dev.
@koseki_stuff
@koseki_stuff 2 жыл бұрын
how
@fricknfrackgames6558
@fricknfrackgames6558 Жыл бұрын
Dani, really great tutorial!!!!
@konamusics1560
@konamusics1560 2 жыл бұрын
Thank you so much that was hugelyyy usefull !
@furkankaraca9028
@furkankaraca9028 Жыл бұрын
thank you so much. you explain so easy and clear.👍👍👍
@cavalcant3
@cavalcant3 Жыл бұрын
bro, i love u i was 3 days trying make this
@_natcho
@_natcho Жыл бұрын
AMAZING TUTORIAL!!!
@giuseppedimaio
@giuseppedimaio 2 жыл бұрын
Thanks, super useful!
@Moon-cr4mu
@Moon-cr4mu 2 жыл бұрын
straightforward and useful tutorial
@HamToFreeHai
@HamToFreeHai 2 жыл бұрын
Very nice explanation👍
@nicolasportu
@nicolasportu 2 жыл бұрын
Cristal Clear :) Just saved one of my begginer's day;
@gabrielsouza9651
@gabrielsouza9651 2 жыл бұрын
Simples but highly effective video! In the middle of development it occured to me forgetting about how reference the object to use its script. It has for sure helped me out, thanks!
@dimitardimitrov7950
@dimitardimitrov7950 Жыл бұрын
lol Thanks grate help i was trying to du that for my UI so i can display ammo count and stuff. thanks again.
@tagscientist
@tagscientist 2 жыл бұрын
Excellent thank you.
@shaunfarley7087
@shaunfarley7087 Жыл бұрын
Thank you for this
@stealthyshiroean
@stealthyshiroean 2 жыл бұрын
Hey, Dani, good tutorial. This was definitely a problem for me when I first started trying to learn Unity about a year ago. Now, I actually think I'm finally getting the hang of it and understanding maybe just a bit more how OOP works in regards to Unity (and I guess in general since I really didn't have any programming background before either lol). Also, sorry if you've mentioned this before, but have you made or are currently working on any games? I know you've said before that game dev has been a passion of yours and you have a lot of insight when it comes to making games when I watch your indie gameplay videos. Would love to check out some of your work if it's out there for public. Also, happy holidays to you and yours if I don't happen to catch one of your videos before the end of the year!
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
Thank you. 😊 I actually don't have any games shared anywhere, since every Unity project I have made are mainly just for my own amusement. I believe I had about 15ish half baked game ideas on my computer that unfortunately got deleted a month ago, when my HDD decided it was time to retire. Currently I have a "P.T." clone (the horror game that everyone keeps copying on Steam and Itchio) that I am making to "prove how easy they are to make" for a future video here on the channel. 🙂 Besides that, I have also just started on developing my first full game, that I am aiming to actually finish. It's a 2D platformer inspired by Norse mythology, and by other games such as Shadow of the Colossus where you focus on 'big monster mechanics', rather than many smaller enemies. I am not planning on showing the development until I have a clearer idea of the mechanics and visual style of the game. 🙂 But when I reach a "comfortable point" then I will definitely do dev vlogs.
@stealthyshiroean
@stealthyshiroean 2 жыл бұрын
@@Dani_Krossing The "P.T." clone is a great idea lol. Will love to see that video in the future. And I think your game idea sounds great! I can't wait for you to start on those dev logs when you get further along.
@pandadog8343
@pandadog8343 2 жыл бұрын
thanks for the video, i was going to make everything in one script
@duddu610
@duddu610 2 жыл бұрын
Now this crack, is just unreal! Thanks for that ;)
@foreducation408
@foreducation408 2 жыл бұрын
really helpful tutorial.
@ms_majhi
@ms_majhi Жыл бұрын
Thank you very much.
@setroinfor_yt3506
@setroinfor_yt3506 2 жыл бұрын
Thanks u helped me
@3jkptradingandservices998
@3jkptradingandservices998 Жыл бұрын
Your so detailed ! SUBBED
@bloiii35
@bloiii35 10 ай бұрын
This was the first time that I didn't replay the same sentence 10 times, watched the video again to understand or get bored and quit the video while learning coding.
@Director414
@Director414 Жыл бұрын
Thanks for a great video! in my case i have different grenades and explosions etc, things that are not in the hierarchy. Should I reference those scripts from my project folders? Or am I doing it wrong somehow? I imagine many scripts won't be in the hierarchy, still you want them to be able to talk to other classes
@ryslanxd8787
@ryslanxd8787 Жыл бұрын
thank you!
@saeidnamdari3150
@saeidnamdari3150 2 жыл бұрын
thanks i love you ♥
@AlternativeAffirmations
@AlternativeAffirmations Жыл бұрын
"Beardlon Musk can't hurt you." Beardlon Musk:
@JohnK68
@JohnK68 2 жыл бұрын
Great video and certainly Dani is one of the best tutors in explaining C#, but you always have to drag and drop stuff in Unity, how do you do the same thing but than in vanilla C#?
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
When you say "vanilla C#", I'm assuming you mean through code and not the editor. 🙂 You would do that using .Find() or .FindGameobjectWithTag() ... However those methods are frowned upon using, unless you have a good reason to. The reason for this, is that whenever you need to locate a certain component or gameobject using code, what happens in the back-end is that it starts searching through ALL your gameobjects in your scene. And that is time consuming and will hurt the games performance. So although it appears "clunky" to drag and drop, it is MUCH better for the overall performance of the game, since the code no longer needs to search through all our gameobjects. 🙂 I totally understand "wanting to do everything through code", but that isn't always the best way to do things.
@erdincatay3715
@erdincatay3715 Жыл бұрын
Bro, you are the best :D
@erdincatay3715
@erdincatay3715 Жыл бұрын
I subscribed and liked :D
@Dark_H9918
@Dark_H9918 6 ай бұрын
my savior !
@TselisoCampbellPK
@TselisoCampbellPK 2 жыл бұрын
great video!
@aslack6145
@aslack6145 2 жыл бұрын
THX YOU
@KamilBandy
@KamilBandy Жыл бұрын
Thank You
@Memress
@Memress 2 жыл бұрын
Thank you
@OmivashkaDlyaRuchek
@OmivashkaDlyaRuchek 4 ай бұрын
THANK YOU SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCH
@aev6075
@aev6075 2 жыл бұрын
Knew the "wrong" way already but the "better" way is nice.
@TheReanim8ted
@TheReanim8ted 2 жыл бұрын
Great Video. You have a great way of explaining things thank you. Just wondering if you know how this works when using prefabs. If my script is on a prefab I can't drag into inspector. I will keep researching either way.
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
Yes you can't drag gameobjects in your scene into the prefab script in the Inspector. It's a precaution so that you don't delete an object in the scene, and mess up references in your prefabs, which creates errors. 🙂 However you can reference other prefabs in the prefab script, since these won't get "deleted" when removed from the current scene. If you meant to ask why you can't edit your prefab and it's component in the Inspector (for example the script), then it is because you need to make sure you click "Edit Prefab" at the top of the prefab in the Inspector.
@TheReanim8ted
@TheReanim8ted 2 жыл бұрын
@@Dani_Krossing thank you master 🙏
@TheReanim8ted
@TheReanim8ted 2 жыл бұрын
Any links to examples of hot to reference prefabs from another prefab then?
@seldatron-6454
@seldatron-6454 Жыл бұрын
Thank you for being the next @Brackeys
@kenj1dev686
@kenj1dev686 2 жыл бұрын
Thanks
@Ebrodrool
@Ebrodrool 7 ай бұрын
merry Christmas!
@Bobrikaz
@Bobrikaz Жыл бұрын
thx u helped me a lot! Let me know if u ever'd want to try my game out :D
@giuseppeserraino227
@giuseppeserraino227 2 жыл бұрын
What if the script I'm trying to reference is tied to multiple objects? would the code still work for every object or simply for the one I am referring to?
@tamasorvos8882
@tamasorvos8882 2 жыл бұрын
Easy to follow, straight to the point. Great tutorial!
@noopstar5122
@noopstar5122 Жыл бұрын
I have a question that Im making mods for a random game and I can able to make asset mods but when assets got scripts attached I can't able to export them to mod file and when I do local hose it says reference scripts are missing so how do I also import those scripts which came with that asset package to the game and make that work
@zixinxu2486
@zixinxu2486 2 жыл бұрын
merci beaucoup!!!
@sh1nyplayer
@sh1nyplayer 2 жыл бұрын
Thank you very much, you have the best tutorial on this by far :)
@troisot1107
@troisot1107 2 жыл бұрын
Could you make tutorial for for player movement like in game Stray?
@Crystal-bq3ow
@Crystal-bq3ow Жыл бұрын
I have a bad habit of failing to drag-and-drop items into scripts so does "Player" mean game object named player or game object with tag player?
@adamaze2920
@adamaze2920 Жыл бұрын
what if the script class is a statemachinebehaviour ... i cant use getcomponent to grab it
@bububulu
@bububulu 2 жыл бұрын
Love you
@Unknown_Games00
@Unknown_Games00 2 жыл бұрын
Can I call the methods which are actually methods like "OnCollisionEnter()" in another script?
@CSR_PaweQ
@CSR_PaweQ Жыл бұрын
hi Dani ! i got one question couse im making a making a game where the score divided by 10 is coins and for coins your buying new things in shop. And the problem is that i want to grab information from scene with level (where is the score) to scene with shop (where are coins) and i need to somehow take those informations together and idk how. Could You help me in anyway?
@dukefleed4280
@dukefleed4280 2 жыл бұрын
ty for the amazing tutorials. I'm a beginner in coding. I understand this guide but my question is that you said always use private type but to access data between scripts you always make them public to access them. so is it ok to use public or not I'm kinda confused. is there any way to access them in private form?
@Dani_Krossing
@Dani_Krossing 2 жыл бұрын
It is perfectly okay to set your fields or methods as public. However in order to minimize any accidental errors, you should always set them to private first, and THEN ask yourself if there is a reason for them to be accessible to everything, in which case they should be public. So no, nothing will break by setting them all public, but it is best practice not to hehe. 🙂
@dukefleed4280
@dukefleed4280 2 жыл бұрын
@@Dani_Krossing ok, thank you very much for the fast reply. your guides are the best for beginners like me
@motionproplus6346
@motionproplus6346 Жыл бұрын
Hey guys. I'm having a problem I did access the variable from another script but the way it's done here doesn't allow for updating the variable. How would I read the varible on update? It seems like it only reads the variable once
@PortalGamer680
@PortalGamer680 Жыл бұрын
how would I change the value with a slider?
@nebitanlik6304
@nebitanlik6304 Жыл бұрын
How i can check if bool from another script gets true ?
@levisparks9346
@levisparks9346 2 жыл бұрын
when i do that i get the error that its security level is too high. everything that can be made public has been, and still its a no go. Any solutions?
How to get a variable from another script in Unity (the right way)
15:44
Game Dev Beginner
Рет қаралды 90 М.
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 28 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 101 МЛН
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 24 МЛН
Be CAREFUL with Scriptable Objects!
8:27
Code Monkey
Рет қаралды 78 М.
Better Coding in Unity With Just a Few Lines of Code
15:27
Firemind
Рет қаралды 305 М.
Breaking up Code in Unity (Important game dev tips for beginners)
18:36
Lost Relic Games
Рет қаралды 124 М.
Unity Basics - How to access other scripts
9:44
MetalStorm Games
Рет қаралды 2,6 М.
Why The Windows Phone Failed
24:08
Apple Explained
Рет қаралды 57 М.
Everything You Need to Know About Singletons in Unity
8:38
Infallible Code
Рет қаралды 86 М.
Programming portals for my DOOM-style FPS
17:15
jdh
Рет қаралды 206 М.
How I learned Unity without following tutorials (Developing 1)
18:11
Game Maker's Toolkit
Рет қаралды 2 МЛН
Uncover the Simple Trick to KEEP MUSIC PLAYING Between Scenes!
4:42
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 28 МЛН