Unity:オブジェクトの傾きを対象物と同じにする

プログラム

例えば対象物がシーン上のオブジェクトPlayerだとして、オブジェクトをPlayerと同じ傾きにしたい場合、オブジェクトにアタッチしたスクリプトで以下のようにする。

1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4  
5public class TestObject : MonoBehaviour
6{
7    private GameObject player;
8 
9    // Start is called before the first frame update
10    void Start()
11    {
12        // プレイヤー情報を取得
13        player = GameObject.Find("Player");
14 
15        // 傾きをプレイヤーと同じにする
16        transform.rotation = player.transform.rotation;
17    }
18  
19    // Update is called once per frame
20    void Update()
21    {
22 
23    }
24}

コメント

タイトルとURLをコピーしました