Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Unityt超入門解説編1 / Unity_introduction_about_getcom...
Search
shota-yano
October 05, 2020
Technology
0
110
Unityt超入門解説編1 / Unity_introduction_about_getcomponent
社内勉強会向け資料
this.GetComponentについて
shota-yano
October 05, 2020
Tweet
Share
More Decks by shota-yano
See All by shota-yano
Kumamoto HoloLens ミートアップ v7 / KumamotoHoloLensMeetupv7
shotayano
0
260
PowerAppsハンズオン準備 / 20220527_PowerApps_Preparation
shotayano
0
91
PowerAppsハンズオン / 20220527_PowerApps_Handson
shotayano
0
270
Power Automate Desktop ハンズオン / powerautomatedesktophandson
shotayano
0
150
PowerAutomateDesktopハンズオン準備 / PowerAutomateDesktopSetup
shotayano
0
130
HoloLens2ハンズオン(MRTKを触ってみる) / hololens2_and_mrtk_demo_handson
shotayano
1
350
HoloLens2開発環境構築 / dev-env-construction-for-hololens2
shotayano
0
220
Spatial Anchorsを活用した経路探索の検討
shotayano
0
1.1k
Azure CustomVision ハンズオン
shotayano
0
160
Other Decks in Technology
See All in Technology
技術的負債解消の取り組みと専門チームのお話 #技術的負債_Findy
bengo4com
1
1.2k
開発者が自律的に AWS Security Hub findings に 対応する仕組みと AWS re:Invent 2024 登壇体験談 / Developers autonomously report AWS Security Hub findings Corresponding mechanism and AWS re:Invent 2024 presentation experience
kaminashi
0
190
技術負債の「予兆検知」と「状況異変」のススメ / Technology Dept
i35_267
1
1k
飲食店予約台帳を支えるインタラクティブ UI 設計と実装
siropaca
6
1.4k
リアルタイム分析データベースで実現する SQLベースのオブザーバビリティ
mikimatsumoto
0
950
明日からできる!技術的負債の返済を加速するための実践ガイド~『ホットペッパービューティー』の事例をもとに~
recruitengineers
PRO
3
100
[2025-02-07]生成AIで変える問い合わせの未来 〜チームグローバル化の香りを添えて〜
tosite
1
290
The 5 Obstacles to High-Performing Teams
mdalmijn
0
270
トラシューアニマルになろう ~開発者だからこそできる、安定したサービス作りの秘訣~
jacopen
2
1.5k
Data-centric AI入門第6章:Data-centric AIの実践例
x_ttyszk
1
370
マルチモーダル理解と生成の統合 DeepSeek Janus, etc... / Multimodal Understanding and Generation Integration
hiroga
0
360
アジャイル開発とスクラム
araihara
0
160
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
Facilitating Awesome Meetings
lara
51
6.2k
Documentation Writing (for coders)
carmenintech
67
4.6k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
The Pragmatic Product Professional
lauravandoore
32
6.4k
Making Projects Easy
brettharned
116
6k
GraphQLとの向き合い方2022年版
quramy
44
13k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1k
A Philosophy of Restraint
colly
203
16k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Agile that works and the tools we love
rasmusluckow
328
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
Transcript
2020/10/05 Unity超入門 解説編1
解説 • GetComponentの解説 • ふわっとした解説ですが…
• Hierarchyウィンドウにある1つ1つがオブジェクト • それぞれが別オブジェクトとして独立 • Cubeが2つあるがこれは形状は同じだが別々のオブジェクト • カメラやライトも1つのオブジェクトとして存在 • 実行ボタンを押した瞬間、各オブジェクトがゲーム内でCreate
オブジェクト オブジェクト オブジェクト オブジェクト オブジェクト オブジェクトの解説
• Sphereオブジェクトの構成要素(コンポーネント) ※どんな機能を持っているか • Transform • Mesh Filter • Mesh
Renderer • Sphere Collider コンポーネントの解説
• Sphereオブジェクトの構成要素(コンポーネント) • Transformコンポーネントの設定項目 • Position:位置を決める • X:水平位置 • Rotation:回転を決める
• Scale:大きさを決める • 他のコンポーネントによってどんな設定ができるのかが決まっている • わからないときは「?」を見ること(もしくは公式ドキュメント) わからないとき コンポーネントの解説
• Textオブジェクトを追加 • わかりやすいよう「DisplayText1」に名前を変更 • Textオブジェクト「 DisplayText1 」のコンポーネント • Rect
Transform • CanvasRenderer • Text コンポーネントの解説
• Textオブジェクト「 DisplayText1 」のコンポーネントについて • Textコンポーネントの設定項目 • Text:表示する文字列を設定する • Character:フォントやフォントサイズなどを設定する
• Paragraph:左寄せなどを設定する • Color:色を設定する • Etc… などが設定可能 コンポーネントの解説
• Textオブジェクトの「DisplayText1」にスクリプトを追加 • DisplayText1のコンポーネントに「StartText(Script)」が追加される • スクリプト名:StartText • 同時にAssetsフォルダに追加される • ここでコンポーネントの中身を管理する
スクリプトの解説
• DisplayText1の「StartText(Script)」コンポーネントについて • DisplayText1オブジェクトのTextコンポーネントのTextの値を変更 • New Text ⇒ GAME START
• デフォルトで2つの関数が作成される • Start関数:オブジェクトがCreateされたときに1回だけ実行 • Update関数:オブジェクトの更新処理(1フレームごと) • ※60FPSなら1秒間に60回実行 スクリプトの解説
• this : このコンポーネントを実行しているオブジェクト • DisplayText1オブジェクト • this.GetComponent<Text>() • DisplayText1オブジェクトに設定されたTextコンポーネントを取得する
• <>はコンポーネント名を指定する • ()はコンポーネントの型。今回はないので指定しない。 • .text : TextコンポーネントのTextという要素を指定 this.GetComponent<Text>().Textの解説
DisplayText1オブジェクト • this : このコンポーネントを実行しているオブジェクト • DisplayText1オブジェクト • this.GetComponent<Text>() •
DisplayText1オブジェクトに設定されたTextコンポーネントを取得する • <>はコンポーネント名を指定する • ()はコンポーネントの型。今回はないので指定しない。 • .text : TextコンポーネントのTextという要素(変数)を指定 this.GetComponent<Text>().Textの解説 Rect Transformコンポーネント PosX:100 PosY:200 PosZ:0 CanvasRenderer コンポーネント Textコンポーネント Text:New Text Width:500 Height:200 Color:383838 StartText コンポーネント
DisplayText2オブジェクト • DisplayText1とDisplayText2は別オブジェクト • DisplayText2オブジェクトにはStartTextコンポーネントはない • 実行後はDisplayText1オブジェクトのみ変化がある DisplayText2を作成 Rect Transformコンポーネント
PosX:100 PosY:100 PosZ:0 Textコンポーネント Text:New Text2 Width:500 Height:200 Color:383838 CanvasRenderer コンポーネント DisplayText1オブジェクト Rect Transformコンポーネント PosX:100 PosY:200 PosZ:0 StartText コンポーネント Textコンポーネント Text:New Text Width:500 Height:200 Color:383838 CanvasRenderer コンポーネント
• https://docs.unity3d.com/ja/current/ScriptReference/GameObject.GetComponent.html リファレンス
END