Skip to content

Instantly share code, notes, and snippets.

@HyroVitalyProtago
Created April 22, 2016 14:15
Show Gist options
  • Select an option

  • Save HyroVitalyProtago/0da89941ff12a6405d2beeaff5dba337 to your computer and use it in GitHub Desktop.

Select an option

Save HyroVitalyProtago/0da89941ff12a6405d2beeaff5dba337 to your computer and use it in GitHub Desktop.
Generic script to always look at a transform
using UnityEngine;
public class AlwaysLookAt : MonoBehaviour {
[SerializeField] Transform _transformToLookAt;
void Update() {
Vector3 v = _transformToLookAt.position - transform.position;
v.x = v.z = 0.0f;
transform.LookAt(_transformToLookAt.position - v);
transform.Rotate(0,180,0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment