1
This commit is contained in:
30
unity/Assets/Script/GameObject/Other/FacingCamera.cs
Normal file
30
unity/Assets/Script/GameObject/Other/FacingCamera.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FacingCamera : MonoBehaviour
|
||||
{
|
||||
Transform[] childs;
|
||||
private Transform cameraMain;
|
||||
private void Awake()
|
||||
{
|
||||
cameraMain = GameObject.FindGameObjectWithTag("Camera").transform;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
childs = new Transform[transform.childCount];
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
childs[i] = transform.GetChild(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
for (int i = 0; i < childs.Length; i++)
|
||||
{
|
||||
childs[i].rotation = cameraMain.rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user