Created
October 17, 2016 20:57
-
-
Save Sammyjroberts/cf02607b2fca4d081e007e19afb30aa2 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
public class LockOn : MonoBehaviour { | |
GameObject target = null; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if(target != null) { | |
var dir = target.transform.position - transform.position; | |
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; | |
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); | |
} | |
} | |
void OnTriggerEnter2D(Collider2D col) { | |
Debug.Log("asdsd"); | |
if(col.tag == "Player") { | |
Debug.Log("ey"); | |
target = col.gameObject; | |
} | |
} | |
void OnTriggerExit2D(Collider2D col) { | |
target = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment