質問編集履歴
4
文章の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,7 +13,8 @@
|
|
13
13
|
using UnityEngine;
|
14
14
|
using UnityEngine.UI;
|
15
15
|
|
16
|
-
public class
|
16
|
+
public class TextureSet : MonoBehaviour
|
17
|
+
{
|
17
18
|
|
18
19
|
const string TEXNAME_SEN1 = "Texture/j_seikai01";
|
19
20
|
|
@@ -21,16 +22,24 @@
|
|
21
22
|
{
|
22
23
|
Texture2D J_SEIKAI01;
|
23
24
|
J_SEIKAI01 = Resources.Load(TEXNAME_SEN1) as Texture2D;
|
25
|
+
GameObject go = GameObject.Find("Panel");
|
26
|
+
if (go)
|
27
|
+
{
|
24
|
-
|
28
|
+
Debug.Log(go.name);
|
29
|
+
}
|
30
|
+
else
|
31
|
+
{
|
32
|
+
Debug.Log("No game object called wibble found");
|
33
|
+
}
|
25
34
|
go.GetComponent<Renderer>().material.mainTexture = J_SEIKAI01;
|
26
35
|
}
|
27
36
|
|
28
37
|
// Update is called once per frame
|
29
|
-
void Update
|
38
|
+
void Update()
|
30
|
-
|
39
|
+
{
|
40
|
+
|
31
|
-
|
41
|
+
}
|
32
42
|
}
|
33
|
-
|
34
43
|
```
|
35
44
|
実行してみると
|
36
45
|
NullReferenceException: Object reference not set to an instance of an object....
|
3
文章の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,44 @@
|
|
1
|
-
unityにてUIのPanelにテクスチャを
|
1
|
+
unityにてUIのPanelにテクスチャをスクリプトから指定して貼りたいと思ったのですが、うまくいきませんでした
|
2
|
-
|
2
|
+
自分でいろいろ調べたのですがよくわからず、とりあえず下記のサイトを参考にやっては見ました
|
3
3
|
|
4
|
+
https://dennou-note.blogspot.com/2014/01/unity_20.html
|
5
|
+
|
6
|
+
私はunityを始めて日が浅く、C#もその時初めて触ったぐらいなのでまだよく書き方がわかっていない状態です
|
7
|
+
|
8
|
+
一応自分で書いてみたプログラムが以下のものです
|
9
|
+
```C#
|
10
|
+
|
11
|
+
using System.Collections;
|
12
|
+
using System.Collections.Generic;
|
13
|
+
using UnityEngine;
|
14
|
+
using UnityEngine.UI;
|
15
|
+
|
16
|
+
public class TexSet : MonoBehaviour {
|
17
|
+
|
18
|
+
const string TEXNAME_SEN1 = "Texture/j_seikai01";
|
19
|
+
|
20
|
+
private void Start()
|
21
|
+
{
|
22
|
+
Texture2D J_SEIKAI01;
|
23
|
+
J_SEIKAI01 = Resources.Load(TEXNAME_SEN1) as Texture2D;
|
24
|
+
GameObject go = null;
|
25
|
+
go.GetComponent<Renderer>().material.mainTexture = J_SEIKAI01;
|
26
|
+
}
|
27
|
+
|
28
|
+
// Update is called once per frame
|
29
|
+
void Update () {
|
30
|
+
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
```
|
35
|
+
実行してみると
|
36
|
+
NullReferenceException: Object reference not set to an instance of an object....
|
37
|
+
というエラーが出たので参照がうまくできていないんだと思うのですがどこがおかしいのかがわかりません
|
38
|
+
(エラー文で「go.Get...」のところがだめだとは言われたのですが何がだめかわかっていない状態です)
|
39
|
+
|
40
|
+
わかる方がいらっしゃいましたら教えていただけると幸いです
|
41
|
+
|
4
42
|
作成環境
|
5
43
|
unity 2017.4.2f2
|
6
44
|
VisualStudio 2017
|
2
質問文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
unityにてUIのPanelにテクスチャを貼りたいのですが、スクリプトから
|
1
|
+
unityにてUIのPanelにテクスチャを貼りたいのですが、スクリプトからテクスチャを指定して貼ることは可能でしょうか?
|
2
|
-
配列名:texName
|
3
|
-
Panel名:Panel
|
4
|
-
としています。
|
5
|
-
|
2
|
+
もし可能であればその方法を教えていただきたいです
|
3
|
+
|
4
|
+
作成環境
|
5
|
+
unity 2017.4.2f2
|
6
|
+
VisualStudio 2017
|
1
文章の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
配列名:texName
|
3
3
|
Panel名:Panel
|
4
4
|
としています。
|
5
|
-
ちょっと説明不足感がするので修正依頼して
|
5
|
+
ちょっと説明不足感がするのでどんどん修正依頼してもらってかまいませんw
|