質問編集履歴
5
説明追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -90,7 +90,7 @@
|
|
90
90
|
```C#
|
91
91
|
this.transform.position = this.transform.root.TransformPoint(Vector2.zero);
|
92
92
|
```
|
93
|
-
「Sample」の文字が薄い。
|
93
|
+
「Sample」の文字が薄い、もしくは、ぼやけている。
|
94
94
|

|
95
95
|
|
96
96
|
両者の違いは上記コードだけです。他の設定は同じままです。
|
4
説明修正。
title
CHANGED
File without changes
|
body
CHANGED
@@ -86,7 +86,7 @@
|
|
86
86
|
「Sample」の文字が濃い。
|
87
87
|

|
88
88
|
|
89
|
-
・TransformPoint
|
89
|
+
・TransformPointで設定した場合。
|
90
90
|
```C#
|
91
91
|
this.transform.position = this.transform.root.TransformPoint(Vector2.zero);
|
92
92
|
```
|
3
追記②
title
CHANGED
File without changes
|
body
CHANGED
@@ -75,4 +75,22 @@
|
|
75
75
|
エラーメッセージ。
|
76
76
|
```
|
77
77
|
Assets\UISample.cs(21,34): error CS1061: 'Transform' does not contain a definition for 'pivot' and no accessible extension method 'pivot' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
|
78
|
-
```
|
78
|
+
```
|
79
|
+
### 追記②
|
80
|
+
|
81
|
+
・Screenで設定した場合。
|
82
|
+
|
83
|
+
```C#
|
84
|
+
this.transform.position = new Vector2(Screen.width/2, Screen.height/2);
|
85
|
+
```
|
86
|
+
「Sample」の文字が濃い。
|
87
|
+

|
88
|
+
|
89
|
+
・TransformPoint
|
90
|
+
```C#
|
91
|
+
this.transform.position = this.transform.root.TransformPoint(Vector2.zero);
|
92
|
+
```
|
93
|
+
「Sample」の文字が薄い。
|
94
|
+

|
95
|
+
|
96
|
+
両者の違いは上記コードだけです。他の設定は同じままです。
|
2
質問追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -50,5 +50,29 @@
|
|
50
50
|
localPositionだけでなく、positionもピボットの位置によって、基準位置が設定されているということでしょうか?
|
51
51
|
~~また、UI Textにアタッチしているスクリプトにおけるthis.transformは、UI TextのRectTransformを参照できていることでしょうか?
|
52
52
|
[リファレンス](https://docs.unity3d.com/ja/current/ScriptReference/RectTransform.html)を見ましたが、transformはゲームオブジェクトにアタッチしているトランスフォームと書かれていて、これがRectTransformを指しているかどうかわかりませんでした。~~
|
53
|
-
|
54
|
-
|
53
|
+
上記調べていくうちに新たな疑問が出てきました。詳細は追記質問に書きました。
|
54
|
+
|
55
|
+
試したこと以外にも、何かおすすめの位置設定方法があれば教えていただきたいです。
|
56
|
+
|
57
|
+
### 追記質問
|
58
|
+
|
59
|
+
this.transformはRectTransformを本当に取得できているのかどうかわかりません。
|
60
|
+
RectTransformを取得できているはずなのに、pivotを取得しようとするとエラーになってしまうのは何故なのでしょうか?
|
61
|
+
```C#
|
62
|
+
[SerializeField]
|
63
|
+
RectTransform rectTransform;
|
64
|
+
|
65
|
+
void Start()
|
66
|
+
{
|
67
|
+
Debug.Log(this.transform); // Text (UnityEngine.RectTransform)
|
68
|
+
Debug.Log(this.rectTransform); // Text (UnityEngine.RectTransform)
|
69
|
+
Debug.Log(this.transform == this.rectTransform); // True
|
70
|
+
Debug.Log(this.transform.pivot); // ※ エラー。
|
71
|
+
Debug.Log(this.rectTransform.pivot); // (0.5, 0.5);
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
75
|
+
エラーメッセージ。
|
76
|
+
```
|
77
|
+
Assets\UISample.cs(21,34): error CS1061: 'Transform' does not contain a definition for 'pivot' and no accessible extension method 'pivot' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
|
78
|
+
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,6 +48,7 @@
|
|
48
48
|
|
49
49
|
試したこと1~3において、どちらにしろ、UI Text自体のピボットは(0.5, 0.5)に設定しておかないとずれてしまうことがわかりました。
|
50
50
|
localPositionだけでなく、positionもピボットの位置によって、基準位置が設定されているということでしょうか?
|
51
|
-
また、UI Textにアタッチしているスクリプトにおけるthis.transformは、UI TextのRectTransformを参照できていることでしょうか?
|
51
|
+
~~また、UI Textにアタッチしているスクリプトにおけるthis.transformは、UI TextのRectTransformを参照できていることでしょうか?
|
52
|
-
[リファレンス](https://docs.unity3d.com/ja/current/ScriptReference/RectTransform.html)を見ましたが、transformはゲームオブジェクトにアタッチしているトランスフォームと書かれていて、これがRectTransformを指しているかどうかわかりませんでした。
|
52
|
+
[リファレンス](https://docs.unity3d.com/ja/current/ScriptReference/RectTransform.html)を見ましたが、transformはゲームオブジェクトにアタッチしているトランスフォームと書かれていて、これがRectTransformを指しているかどうかわかりませんでした。~~
|
53
|
+
→this.transformは、RectTransformのようでした(間違っていたらご指摘お願いします)。
|
53
54
|
試したこと以外にも、何かおすすめの位置設定方法があれば教えていただきたいです。
|