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

質問編集履歴

5

説明追記

2020/02/15 15:28

投稿

退会済みユーザー
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
  ![イメージ説明](79e3d1ca9bb0827fff4eeed365d377cc.png)
95
95
 
96
96
  両者の違いは上記コードだけです。他の設定は同じままです。

4

説明修正。

2020/02/15 15:28

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -86,7 +86,7 @@
86
86
  「Sample」の文字が濃い。
87
87
  ![イメージ説明](fd774e98719bd84fdb200ac01d347cd4.png)
88
88
 
89
- ・TransformPoint
89
+ ・TransformPointで設定した場合。
90
90
  ```C#
91
91
  this.transform.position = this.transform.root.TransformPoint(Vector2.zero);
92
92
  ```

3

追記②

2020/02/15 15:26

投稿

退会済みユーザー
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
+ ![イメージ説明](fd774e98719bd84fdb200ac01d347cd4.png)
88
+
89
+ ・TransformPoint
90
+ ```C#
91
+ this.transform.position = this.transform.root.TransformPoint(Vector2.zero);
92
+ ```
93
+ 「Sample」の文字が薄い。
94
+ ![イメージ説明](79e3d1ca9bb0827fff4eeed365d377cc.png)
95
+
96
+ 両者の違いは上記コードだけです。他の設定は同じままです。

2

質問追記

2020/02/15 15:25

投稿

退会済みユーザー
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
- →this.transformは、RectTransformのようでした(間違っていたらご指摘お願いします)
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

追記

2020/02/09 06:54

投稿

退会済みユーザー
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
  試したこと以外にも、何かおすすめの位置設定方法があれば教えていただきたいです。