Nextrek
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { public static GameManager Instance; public Transform[] spaceShipPrefebs; public Transform explosionEffect; public static string HERO_NAME = "Player"; public static string ENEMY_NAME = "Enemy"; public static string ALLY_NAME = "Ally"; void Awake() { Instance = this; int heroShipType = 0; if (GlobalObject.Instance) { heroShipType = GlobalObject.Instance.shipType; } else { Debug.LogError("GlobalObject.Instance is NULL!"); } CreateHero(spaceShipPrefebs[heroShipType]); } public static Transform CreateHero(Transform template) { Transform tp = Instantiate(template, Vector3.zero, Quaternion.identity) as Transform; //tp.tag = HERO_NAME; return tp; } public static Transform CreateEnemy(Transform template) { Transform tp = Instantiate(template, Vector3.zero, Quaternion.identity) as Transform; // Defined in prefabs // tp.tag = ENEMY_NAME; return tp; } public static Transform CreateAlly(Transform template) { Transform tp = Instantiate(template, Vector3.zero, Quaternion.identity) as Transform; // Defined in prefabs // tp.tag = ALLY_NAME; return tp; } public static Transform GetHero() { GameObject heroGameObject = GameObject.FindGameObjectWithTag(HERO_NAME); if (heroGameObject != null) { return heroGameObject.transform; } return null; } public static GameObject GetClosestEnemy(Transform observer) { GameObject[] enemies = GameObject.FindGameObjectsWithTag(ENEMY_NAME); GameObject closest = null; float bestScore = Mathf.Infinity; foreach(GameObject enemy in enemies) { Vector3 relativePosition = enemy.transform.position - observer.transform.position; float distance = relativePosition.magnitude; relativePosition.Normalize(); // -1 0 +1 -> 3 2 1 float penalty = (2.0f - Vector3.Dot(observer.transform.forward, relativePosition)) / 3.0f; float score = distance * penalty * penalty * penalty; if (score < bestScore) { bestScore = score; closest = enemy; } } /* if (closest) { Debug.Log("Found: " + closest.transform.position.ToString()); } else { Debug.Log("Nothing FOUND!!"); }*/ return closest; } void Start() { } // Update is called once per frame void Update () { if (Input.GetKey (KeyCode.Escape)) { Application.Quit(); } if (Input.GetKey (KeyCode.Z)) { CommunicationCenter.Instance.ShowSmallCamera(true); } } } |
Commits for Nextrek/3DSpace/Assets/Custum/Scripts/GameManager.cs
Revision | Author | Commited | Message |
---|---|---|---|
127 Diff | DRuega | Thu 06 Nov, 2014 16:52:49 +0000 | Aggiungo PilotNameGenerator.cs Genera nomi random alle navi... così sembra più figo :) :) |
126 Diff | DRuega | Thu 06 Nov, 2014 14:45:25 +0000 | Cleanup, warnings e altre minchiate :) |
125 Diff | DRuega | Thu 06 Nov, 2014 13:44:02 +0000 | Migliorata la ricerca del nemico più vicino pesando di più la differenza angolare. |
122 Diff | DRuega | Thu 06 Nov, 2014 10:12:00 +0000 | Tocco Magico :P |
119 Diff | LMancini | Wed 05 Nov, 2014 15:33:48 +0000 | |
117 Diff | DRuega | Tue 28 Oct, 2014 13:39:51 +0000 | |
112 Diff | FMMortaroli | Thu 09 Oct, 2014 14:21:59 +0000 | |
107 | FMMortaroli | Thu 09 Oct, 2014 11:56:46 +0000 |