How to Pass a Variable from One Script to Another in Unity using C Sharp? EASY

preview_player
Показать описание
How do you access a variable on another script using C#?

eg I have to access myScore on scriptB

Difficulty: Beginner.

Head over the Unity 3D News Blog for more content.

If you enjoyed this video, please consider supporting the tutorials by clicking the link below. Thanks and Happy Coding!

Subscribe:
Рекомендации по теме
Комментарии
Автор

omg i watched like 100 different videos trying to figure out a way how it works and yours is the ONLY VIDEO that helped me!!! THANK YOU! I dont understand why your video has more dislikes than likes! THANK YOU SO MUCH!

joshualippss
Автор

Hey. for future reference your mic recording is too loud. That is all

danespacey
Автор

Thanks for your time and your help 👍👍👍👍👍

CanisMajoris_star
Автор

Thank you man, you're my hero for today! :)

jordymous
Автор

Does this still work for unity 5.1 ?I get "NullReferenceException: Object reference not set to an instance of an object
scripta.addOneToMyScore"

Thanks

clj
Автор

So is this just another way to do GetComponent? Or not quite a replacement?

fennaru
Автор

NullReferenceException: Object reference not set to an instance of an object
Inventory.Start () (at
Can you help I get this error I'm using Unity 4.6.9 and C# scripts

diamondminer
Автор

Keep getting "Object reference not set to an instance of an object", is this an old method that no longer works? I'm simply trying to pass a single array using this exact method and it doesnt seem to want to function

dobhamighabbas
Автор

an object reference is required for non-static, field, method, or property.

Can you please help me to solving this error, i am using unity 5.2 and c sharp script

varunmunagala
Автор

I would like to access my currentHealth value that's on my Player script and take that currentHealth value and have it sync over to my PlayerUI script which handles all the GUI's in the game, how would I do that? P.S the currentHealth value is a SyncVar on the Player script and that same value needs to be carried over to display on the GUI which is handled in my PlayerUI script.

Redec
Автор

You need a reference to a specific object where the script is atached.
Example:
class ScriptA {
GameObject go =
ScriptB objectB = go.GetComponent<ScriptB>();
objectB.yourFunction();
}

ramonjanousch
Автор

1:23 if i setup private int myScore it doesn't work.
public int myScore;
does

angreeee
Автор

This is pretty epic
*Here for Ludum Dare 44*

imbrentengle
Автор

HMMerror CS0122; ScriptB.myScore' is inaccessible due to ist protection Level....

schattenlink
Автор

4:40 "MY STRONG!" that part kills me XD XD XD
PD: the mic recording is good I don't have problems with that :D

eziostone
Автор

Good tutorial, too bad I suck at scripting hehe

kojirohiori
Автор

I have so many question for that thimbnail

maindepth
welcome to shbcf.ru