Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Obracaniekurwa : MonoBehaviour {
  5.  
  6. // Use this for initialization
  7. void Start () {
  8.  
  9. }
  10.  
  11. // Jebane unity
  12. void Update () {
  13. Vector3 mousePos = Input.mousePosition; //get mouse position
  14. Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position); //Get object position and put it "on the screen" (same as mouse)
  15. Vector3 offset = new Vector3(mousePos.x - screenPos.x, mousePos.y - screenPos.y); //Check where the mouse is relative to the object
  16.  
  17. float angle = Mathf.Atan2(offset.x, offset.y) * Mathf.Rad2Deg; //Turn that into an angle and convert to degrees
  18. transform.rotation = Quaternion.AngleAxis(angle, Vector3.back); //Set the object's rotation to ve of the angle over -Z
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement