Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- [ExecuteInEditMode]
- [ExecuteInEditMode]
- public class ScreenPosition : MonoBehaviour
- {
- [SerializeField]
- private Vector3 _position = new Vector3(0, 0, 10);
- public Vector3 position{
- get{
- return _position;
- }
- set{
- isChange = true;
- _position = value;
- transform.position = Camera.main.ScreenToWorldPoint(_position);
- }
- }
- private bool isChange = false;
- void Update()
- {
- if( transform.hasChanged && isChange == false ){
- _position = Camera.main.WorldToScreenPoint(transform.position);
- }else{
- isChange = false;
- }
- }
- void OnValidate()
- {
- position = _position;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement