Skip to content

Instantly share code, notes, and snippets.

@leventeren
Created October 6, 2020 20:30
Show Gist options
  • Save leventeren/7d2a50da0bbbde86da1d13391e526255 to your computer and use it in GitHub Desktop.
Save leventeren/7d2a50da0bbbde86da1d13391e526255 to your computer and use it in GitHub Desktop.
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