Last active
April 17, 2018 13:33
-
-
Save todorok1/357c53ba6c9f877848ccda6377ea4297 to your computer and use it in GitHub Desktop.
Unityチュートリアル・ガイド用のPrefabをインスタンス化するスクリプト。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class GuideManager : MonoBehaviour { | |
// 『Sphere』オブジェクトへの参照 | |
[SerializeField] | |
GameObject player; | |
// 『Sphere』オブジェクトから見た相対的なガイドの位置 | |
Vector3 relativePos = new Vector3(2.0f, 2.0f, 0f); | |
void Start(){ | |
// Prefabをインスタンス化するメソッドを呼ぶ | |
InstantiateGuidePrefabs(); | |
} | |
void Update(){ | |
} | |
void InstantiateGuidePrefabs(){ | |
// 『GuideParent』の位置を『Sphere』オブジェクトの位置へ移動 | |
gameObject.transform.position = player.transform.position; | |
//『GuideParent』の位置にrelativePosを足してPrefabの位置を決定 | |
Vector3 guidePos = gameObject.transform.position + relativePos; | |
// Prefabをロードする | |
GameObject guidePrefab = (GameObject)Resources.Load("Prefabs/Guide"); | |
// Prefabをインスタンス化 | |
GameObject guideObject = (GameObject)Instantiate(guidePrefab, guidePos, Quaternion.identity); | |
// インスタンス化したオブジェクトをGuideParentの子オブジェクトにする | |
guideObject.transform.SetParent(gameObject.transform); | |
// オブジェクト名を設定する | |
guideObject.name = "GuideFromScript"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment