

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 AllyShip : MonoBehaviour { public SU_Thruster[] thrusters; public float rollRate = 100.0f; public float yawRate = 30.0f; public float pitchRate = 100.0f; public Vector3[] weaponMountPoints; public Transform[] laserShotPrefab; public AudioClip[] soundEffectFire; public CameraFollow followCamera; public float life = 100; private bool isAlive = true; private Rigidbody _cacheRigidbody; private float shootFreq = 1f; private float lastShootTime = 0; private int weaponType = 0; private GameObject currentEnemyTarget; private static float ROTATION_SPEED = 0.75f; // degrees private static float SHOOT_RANGE = 2000.0f; private static float MIN_ENGAGE_RANGE = 300.0f; private static float HERO_MIN_RANGE = 1000.0f; private static float HERO_MAX_RANGE = 2000.0f; float genCoord(float min_distance, float max_distance) { return (Random.value - Random.value) * (min_distance + Random.value * (max_distance-min_distance)); } void Start() { this.transform.position = new Vector3( genCoord(HERO_MIN_RANGE, HERO_MAX_RANGE), genCoord(HERO_MIN_RANGE, HERO_MAX_RANGE), genCoord(HERO_MIN_RANGE, HERO_MAX_RANGE) ); this.transform.rotation = Random.rotation; foreach (SU_Thruster _thruster in thrusters) { if (_thruster == null) { Debug.LogError("Thruster array not properly configured. Attach thrusters to the game object and link them to the Thrusters array."); } } _cacheRigidbody = rigidbody; if (_cacheRigidbody == null) { Debug.LogError("Spaceship has no rigidbody - the thruster scripts will fail. Add rigidbody component to the spaceship."); } } public void getHitted(float hit) { if (!isAlive) return; life -= hit; if (life<=0) { isAlive = false; Instantiate(GameManager.Instance.explosionEffect, this.transform.position, this.transform.rotation); CommunicationCenter.Instance.DestroyOneAlly(this.gameObject); Destroy(this.gameObject); } } void StartThruster() { foreach (SU_Thruster _thruster in thrusters) { _thruster.StartThruster(); } } void StopThruster() { foreach (SU_Thruster _thruster in thrusters) { _thruster.StopThruster(); } } void Update() { lastShootTime+=Time.deltaTime; if (currentEnemyTarget == null) { //Debug.Log ("Find target"); currentEnemyTarget = GameManager.GetClosestShip(GameManager.ENEMY_TAG, this.gameObject); } if (currentEnemyTarget) { Transform enemyShip = currentEnemyTarget.transform; Debug.DrawLine(transform.position, enemyShip.position, Color.yellow); //transform.LookAt(enemyShip); Vector3 relative = enemyShip.position - transform.position; float distance = relative.magnitude; relative.Normalize(); //Debug.DrawLine (this.transform.position, this.transform.position + targetDir*100.0f, Color.green); float step = ROTATION_SPEED * Time.deltaTime; Vector3 newDir = Vector3.RotateTowards (this.transform.forward, relative, step, 0.0f); this.transform.rotation = Quaternion.LookRotation (newDir); if (distance<MIN_ENGAGE_RANGE) { StopThruster(); } else { StartThruster(); } if ((distance<SHOOT_RANGE) && (Vector3.Dot (relative, transform.forward)>0.5) && (lastShootTime>shootFreq)) { lastShootTime=0; foreach (Vector3 _wmp in weaponMountPoints) { // Calculate where the position is in world space for the mount point Vector3 _pos = transform.position + transform.right * _wmp.x + transform.up * _wmp.y + transform.forward * _wmp.z; // Instantiate the laser prefab at position with the spaceships rotation // Specify which transform it was that fired this round so we can ignore it for collision/hit //Transform _laserShot = (Transform) Instantiate(laserShotPrefab[weaponType], _pos, transform.rotation); //_laserShot.GetComponent<SU_LaserShot>().firedBy = transform; WeaponFireUtils.FireLaser(laserShotPrefab[weaponType], _pos, this.transform.rotation, this.gameObject, GameManager.ENEMY_TAG); } if (soundEffectFire[weaponType] != null) { audio.PlayOneShot(soundEffectFire[weaponType]); } } } } } |
Commits for Nextrek/3DSpace/Assets/Custum/Scripts/AllyShip.cs
Revision | Author | Commited | Message |
---|---|---|---|
147
![]() |
![]() |
Thu 20 Nov, 2014 15:51:08 +0000 | |
146
![]() |
![]() |
Wed 19 Nov, 2014 17:44:49 +0000 | |
144
![]() |
![]() |
Mon 17 Nov, 2014 15:18:43 +0000 | |
141
![]() |
|
Fri 14 Nov, 2014 08:20:17 +0000 | Primo tentativo di unificare le procedure di fuoco delle armi. Passo necessario per far si che i nemici possano sparare i missili |
139
![]() |
|
Mon 10 Nov, 2014 21:34:58 +0000 | I nemici ora se la prendono pure con gli alleati, non puntano solo il giocatore. |
138
![]() |
|
Mon 10 Nov, 2014 18:41:38 +0000 | AllyShip: Smooth Step Rotation. |
134
![]() |
|
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). |
131
![]() |
|
Thu 06 Nov, 2014 18:25:48 +0000 | Merge. |
130
![]() |
![]() |
Thu 06 Nov, 2014 18:03:48 +0000 | |
127 |
|
Thu 06 Nov, 2014 16:52:49 +0000 | Aggiungo PilotNameGenerator.cs Genera nomi random alle navi... così sembra più figo :) :) |