Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Global : MonoBehaviour
- {
- private static Global instance;
- private static Plane screenPlane;
- void Awake()
- {
- if (!instance)
- {
- instance = this;
- DontDestroyOnLoad(gameObject);
- InitFirst();
- }
- else
- {
- Destroy(gameObject);
- }
- }
- void Start()
- {
- InitScene();
- }
- void OnLevelWasLoaded()
- {
- InitScene();
- }
- void InitFirst()
- {
- // for iOS
- Application.targetFrameRate = 60;
- // create plane used to detect world position
- screenPlane = new Plane(-Vector3.forward, Vector3.zero);
- }
- void InitScene()
- {
- // ...
- }
- public static Vector3 GetWorldPosition(Vector2 point)
- {
- Ray ray = Camera.main.ScreenPointToRay(point);
- float distance = 0.0f;
- if (screenPlane.Raycast(ray, out distance))
- {
- Vector3 vec = ray.GetPoint(distance);
- return vec;
- }
- return Vector3.zero;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement