Create a gist now

Instantly share code, notes, and snippets.

Rotate sample component
using UnityEngine;
using System.Collections;
public class RotateTest : MonoBehaviour
{
public GameObject target;
public Vector3 additional;
Quaternion _rot;
Quaternion _initRot;
Vector3 _vec;
// Use this for initialization
void Start ()
{
_initRot = transform.rotation;
_rot = Quaternion.identity;
_vec = transform.position - target.transform.position;
}
// Update is called once per frame
void Update ()
{
_rot *= Quaternion.AngleAxis (180f * Time.deltaTime, Vector3.up);
var r = _rot * Quaternion.Euler (additional);
transform.position = r * _vec + target.transform.position;
transform.rotation = r * _initRot;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment