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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
using UnityEngine; using System.Collections; public class GameManager : MonoBehaviour { public static GameManager Instance; public Transform[] spaceShipPrefebs; public Transform explosionEffect; public static string HERO_TAG = "Player"; public static string ENEMY_TAG = "Enemy"; public static string ALLY_TAG = "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_TAG); if (heroGameObject != null) { return heroGameObject.transform; } return null; } public static GameObject GetClosestEnemy(Transform observer) { GameObject[] enemies = GameObject.FindGameObjectsWithTag(ENEMY_TAG); 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; } public static void HandleWeaponHit(RaycastHit _hit, float hitPower, Transform firedBy, Transform explosionEffect, Quaternion _rotation) { if(_hit.transform.tag==HERO_TAG && firedBy.tag!=HERO_TAG) { Life l = _hit.transform.GetComponent<Life>(); if(l!=null) l.getHitted(hitPower); CommunicationCenter.Instance.ShowSmallCamera2(true); } else if(_hit.transform.tag==ENEMY_TAG) { EnemyShip es = _hit.transform.GetComponent<EnemyShip>(); if(es!=null) es.getHitted(hitPower); } else if(_hit.transform.tag==ALLY_TAG) { AllyShip a = _hit.transform.GetComponent<AllyShip>(); if(a !=null) a.getHitted(hitPower); } else if (_hit.transform.tag!=HERO_TAG && Random.Range(0,20) < 2) { MessageWindow.Instance.NewMessage ("An asteroid has been destroyed"); // Instantiate the explosion effect at the point of impact Instantiate(explosionEffect, _hit.transform.position, _rotation); // Destroy the game object that we just hit Destroy(_hit.transform.gameObject); } } void Start() { } // Update is called once per frame void Update () { if (Input.GetKey (KeyCode.Escape)) { Application.Quit(); } if (Input.GetKey (KeyCode.Z)) { CommunicationCenter.Instance.ShowSmallCamera1(true); } } } |
Commits for Nextrek/3DSpace/Assets/Custum/Scripts/GameManager.cs
Revision | Author | Commited | Message |
---|---|---|---|
134 Diff | DRuega | Fri 07 Nov, 2014 18:48:12 +0000 | In GameManager ho aggiunto HandleWeaponHit per centralizzare e generalizzare la gestione degli impatti delle armi (SU_LaserShot e Missile). |
130 Diff | LMancini | Thu 06 Nov, 2014 18:03:48 +0000 | |
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 |