티스토리 뷰
I show How to refer to a variable in other files.
(refer to a variable of class being componentization)
2 GameObjects, 2 files Each objects have.
How to refer to the value of speed variable in GameManager class.
1. In Source code
public class GameManager : MonoBehaviour {
PlayerControl pc;
void Start () {
GameObject obj = GameObject.Find ("Player");
if (obj != null)
pc = obj.GetComponent<PlayerControl>();
Debug.Log ("speed : " + pc.speed);
}
void Update () {
}
}
2. in Unity Editor
1) Variable definition of PlayerControl class type
public class GameManager : MonoBehaviour {
public PlayerControl pc;
void Start () {
Debug.Log ("speed : " + pc.speed);
}
void Update () {
}
}
2)
you play the game, you cans see an error like below
You have to connect reference variable of "pc".
NullReferenceException: Object reference not set to an instance of an object
GameManager.Start () (at Assets/Scripts/GameManager.cs:8)
Choose GUI Obejct, drag and drop over the variable "pc" of GameManager component.
and then you use the variable of "speed" of PlayerControl class the same as number 1.
'Programming Tip' 카테고리의 다른 글
[Anrdoid] How to use ScrollView (0) | 2016.06.29 |
---|---|
[Anrdoid] how to fix ACTION_DIAL Exception of Implicit Intent (0) | 2016.06.28 |
[Unity] C# Scripting rule in Unity (0) | 2016.06.26 |
[Android]BlurMaskFilter doesn't work, how to fix the error (0) | 2016.06.25 |
[Android]Useful Eclipse shortcut/hot key (0) | 2016.06.25 |
- Total
- Today
- Yesterday
- home sewing
- jeans to a bag
- sewing tutorial
- recycle jeans
- easy sewing
- sewing skirts
- without a pattern
- Reconstruct jeans
- jean to skirt
- chiffon skirts
- how to sew ciffon skirts
- sewing a dress
- reuse jeans
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |