Advertisement
infinite_ammo

Global.cs

Sep 8th, 2012
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Global : MonoBehaviour
  5. {
  6.     private static Global instance;
  7.  
  8.     private static Plane screenPlane;
  9.  
  10.     void Awake()
  11.     {
  12.         if (!instance)
  13.         {
  14.             instance = this;
  15.             DontDestroyOnLoad(gameObject);
  16.             InitFirst();
  17.         }
  18.         else
  19.         {
  20.             Destroy(gameObject);
  21.         }
  22.     }
  23.  
  24.     void Start()
  25.     {
  26.         InitScene();
  27.     }
  28.  
  29.     void OnLevelWasLoaded()
  30.     {
  31.         InitScene();
  32.     }
  33.  
  34.     void InitFirst()
  35.     {
  36.         // for iOS
  37.         Application.targetFrameRate = 60;
  38.         // create plane used to detect world position
  39.         screenPlane = new Plane(-Vector3.forward, Vector3.zero);
  40.     }
  41.  
  42.     void InitScene()
  43.     {
  44.         // ...
  45.     }
  46.  
  47.     public static Vector3 GetWorldPosition(Vector2 point)
  48.     {
  49.         Ray ray = Camera.main.ScreenPointToRay(point);
  50.         float distance = 0.0f;
  51.         if (screenPlane.Raycast(ray, out distance))
  52.         {
  53.             Vector3 vec = ray.GetPoint(distance);
  54.             return vec;
  55.         }
  56.         return Vector3.zero;
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement