Last active
August 29, 2015 14:23
-
-
Save tarob19/81bec64893ecde2fe454 to your computer and use it in GitHub Desktop.
Rotate sample component
This file contains hidden or 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 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