Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. [ExecuteInEditMode]
  5. [ExecuteInEditMode]
  6. public class ScreenPosition : MonoBehaviour
  7. {
  8. [SerializeField]
  9. private Vector3 _position = new Vector3(0, 0, 10);
  10. public Vector3 position{
  11. get{
  12. return _position;
  13. }
  14. set{
  15. isChange = true;
  16. _position = value;
  17. transform.position = Camera.main.ScreenToWorldPoint(_position);
  18. }
  19. }
  20.  
  21. private bool isChange = false;
  22.  
  23. void Update()
  24. {
  25. if( transform.hasChanged && isChange == false ){
  26. _position = Camera.main.WorldToScreenPoint(transform.position);
  27. }else{
  28. isChange = false;
  29. }
  30. }
  31.  
  32. void OnValidate()
  33. {
  34. position = _position;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement