teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

助けて下さい

2020/04/01 17:05

投稿

kidaer
kidaer

スコア31

title CHANGED
File without changes
body CHANGED
@@ -19,7 +19,7 @@
19
19
  }
20
20
  }===========================
21
21
  上記で入るようになりました。
22
- しかし別のシーンからsintを呼び出そうとして
22
+ しかし別のシーンからaaaを呼び出そうとして
23
23
  ========================
24
24
  using System.Collections;
25
25
  using System.Collections.Generic;
@@ -27,7 +27,6 @@
27
27
  using System;
28
28
  using UnityEngine.UI;
29
29
 
30
-
31
30
  public class 文字変数 : MonoBehaviour {
32
31
 
33
32
  public GameObject score_object = null; // Textオブジェクト
@@ -39,12 +38,22 @@
39
38
  // 更新
40
39
  void Update () {
41
40
  // オブジェクトからTextコンポーネントを取得
41
+ int b = titleJup.aaa;
42
42
 
43
43
  Text score_text = score_object.GetComponent<Text> ();
44
44
  // テキストの表示を入れ替える
45
- score_text.text = aaa;
45
+ score_text.text = b;
46
46
  }
47
47
  }
48
48
  =========================
49
- とするですが再生できずにいます
49
+ 今こ状態から進めずにいます
50
+ score_text.text = b;を"b"にすれば再生できるのですが、変数にすると再生できなくなります。
51
+ またエラーが出ています
52
+ =========================
53
+ Cannot implicitly convert type `int' to `String'
54
+ これともうひとつ
55
+ All compiler errors have be fixed before you can playmodo!
56
+ unityEdter.SceneVieW:ShowCompileErrorNotification()(atC:/buikdskave/unity/build/Editor/Mono/SceneView/SceneView.cs:2935)
57
+ =================================================
58
+ 上記の内容がでており、ぐぐったのですがよくわかりませんでした。
50
- どうしたらいいでしょうか?
59
+ どうしたらいいでしょうか?

2

一文抜けていたので修正しました

2020/04/01 17:05

投稿

kidaer
kidaer

スコア31

title CHANGED
File without changes
body CHANGED
@@ -9,6 +9,7 @@
9
9
 
10
10
  public class titleJup : MonoBehaviour {
11
11
 
12
+ public static int aaa;
12
13
  // ボタンが押された場合、今回呼び出される関数
13
14
  public void OnClick()
14
15
  {

1

状況が変わったので質問を更新しました

2020/04/01 16:18

投稿

kidaer
kidaer

スコア31

title CHANGED
File without changes
body CHANGED
@@ -1,16 +1,49 @@
1
1
  シーンを跨いで使える変数を設定したいです
2
2
  【今やっていること】
3
3
  =======================
4
+ using System.Collections;
5
+ using System.Collections.Generic;
4
6
  using UnityEngine;
7
+ using UnityEngine.SceneManagement;
8
+ using UnityEngine.UI;
9
+
10
+ public class titleJup : MonoBehaviour {
5
11
 
6
- public class 変宣言 : MonoBehaviour {
12
+ // ボタンが押された場合、今回呼び出される関
7
- {
8
- public void Start () {
13
+ public void OnClick()
9
14
  {
10
- public static int score = 0;
15
+ int aaa = (Random.Range (1, 10));
16
+ Debug.Log(aaa); // ログを出力
17
+ SceneManager.LoadScene("画面2");
11
18
  }
19
+ }===========================
20
+ 上記で入るようになりました。
21
+ しかし別のシーンからsintを呼び出そうとして
22
+ ========================
23
+ using System.Collections;
24
+ using System.Collections.Generic;
25
+ using UnityEngine;
26
+ using System;
27
+ using UnityEngine.UI;
28
+
29
+
30
+ public class 文字変数 : MonoBehaviour {
31
+
32
+ public GameObject score_object = null; // Textオブジェクト
33
+
34
+ // 初期化
35
+ void Start () {
36
+ }
37
+
38
+ // 更新
39
+ void Update () {
40
+ // オブジェクトからTextコンポーネントを取得
41
+
42
+ Text score_text = score_object.GetComponent<Text> ();
43
+ // テキストの表示を入れ替える
44
+ score_text.text = aaa;
45
+ }
12
46
  }
13
- ========================
47
+ ========================
14
- シーン間で共有する変数にはpublicをつけると見たのですが再生すらでき状態で
48
+ するのですが再生できずに
15
- どうしたらいいでしょうか?
49
+ どうしたらいいでしょうか?
16
- よろしくお願いします