Created
October 6, 2020 20:30
-
-
Save leventeren/7d2a50da0bbbde86da1d13391e526255 to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
using System.Collections; | |
public class TransformHelper | |
{ | |
public static Transform FindChild(Transform parent, string goName) | |
{ | |
var child = parent.Find(goName); | |
if (child != null) return child; | |
for (int i = 0; i < parent.childCount; i++) | |
{ | |
child = parent.GetChild(i); | |
var go = FindChild(child, goName); | |
if (go != null) return go; | |
} | |
return null; | |
} | |
public static void LookAtTarget(Vector3 targetDir, Transform transform, | |
float rotationSpeed) | |
{ | |
if (targetDir != Vector3.zero) | |
{ | |
Quaternion targetRotation = Quaternion.LookRotation(targetDir); | |
transform.rotation = Quaternion.Lerp(transform.rotation, | |
targetRotation, rotationSpeed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment