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 |
using UnityEngine; using System.Collections; public class Missile : MonoBehaviour { public Transform impactEffect; public Transform explosionEffect; public Transform head; private GameObject target; private float _timer = 0; private int autoDestructionCountDown = 5; private float _speed = 350; private static float ROTATION_SPEED = 1.0f; private float hitPower = 100000; //private bool isActive = false; private Transform firedBy; // "Fired By" Reference to ignore collision detection for the ship that fired the laser public void SetFiredBy(Transform who) { firedBy = who; } void Update() { //(isActive==false)return; _timer -= Time.deltaTime; if (_timer < 0.0f) { _timer += 1.0f; autoDestructionCountDown--; if (autoDestructionCountDown<0) { Instantiate(impactEffect, transform.position, transform.rotation); Destroy(gameObject); return; } Debug.Log ("Re-evaluating target"); target = GameManager.GetClosestEnemy(this.transform); } if (target!=null) { //transform.LookAt(target); float step = ROTATION_SPEED * Time.deltaTime; Vector3 targetDir = target.transform.position - this.transform.position; targetDir.Normalize(); Vector3 newDir = Vector3.RotateTowards (this.transform.forward, targetDir, step, 0.0f); this.transform.rotation = Quaternion.LookRotation (newDir); Debug.DrawLine(this.transform.position, target.transform.position, Color.cyan); } Vector3 _direction = transform.forward*_speed*Time.deltaTime; float _distance = _direction.magnitude; Vector3 startPosition = transform.position; // advance transform.position += _direction; if(_distance>0) { RaycastHit _hit; if (Physics.Raycast(startPosition, _direction, out _hit, _distance*5)) { Debug.Log("raycast: " + _hit.transform.gameObject.tag); if (_hit.transform != firedBy && !_hit.collider.isTrigger) { Quaternion _rotation = Quaternion.FromToRotation(Vector3.up, _hit.normal); Instantiate(impactEffect, _hit.point, _rotation); GameManager.HandleWeaponHit(_hit, hitPower, firedBy, explosionEffect, _rotation); Destroy(gameObject); } } } } } |
Commits for Nextrek/3DSpace/Assets/Custum/Scripts/Missile.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). |
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. |
112 Diff | FMMortaroli | Thu 09 Oct, 2014 14:21:59 +0000 | |
107 | FMMortaroli | Thu 09 Oct, 2014 11:56:46 +0000 |