Exemple #1
0
        /// <summary>
        /// Places and initializes the Tower at the specified position.
        /// </summary>
        /// <param name="position">Position.</param>
        public void Place(Vec3 position)
        {
            Entity.Position = position + new Vec3(0, 0, 2f);

            AddComponent <SineWaveMovement>();
            weapon  = AddComponent <WeaponProjectile>();
            sensor  = AddComponent <TowerSensor>();
            rotator = AddComponent <TurretRotator>();

            // Set weapon target when an enemy is in range
            sensor.OnTargetChanged += Sensor_OnTargetChanged;

            // Stop firing weapon once no targets are in range
            sensor.OnNoTargetsFound += Sensor_OnNoTargetsFound;

            // Set rotator which controls the rotation of the tower's turret
            rotator.AimingFinished += Rotator_AimingFinished;

            SetupWeapon();
        }
Exemple #2
0
 protected override void Start()
 {
     base.Start();
     if (rotatable)
     {
         turretRotator = gameObject.GetComponent <TurretRotator>();
         if (turretRotator == null)
         {
             Debug.LogWarning("missing turret rotator component");
         }
     }
     if (targetingEnemys)
     {
         turretTargetEnemy = gameObject.GetComponent <TurretTargetEnemy>();
         if (turretTargetEnemy == null)
         {
             Debug.LogWarning("missing turret rotator component");
         }
     }
     if (useTargetHelper)
     {
         targetHelper = gameObject.GetComponent <TurretTargetHelper>();
         if (targetHelper == null)
         {
             Debug.LogWarning("missing turret target helper component");
         }
     }
     if (shootingBullets)
     {
         weaponController = gameObject.GetComponentInChildren <Gun>();
         if (weaponController == null)
         {
             Debug.LogWarning("missing turret rotator component");
         }
         weaponController.SpreadMod = autoSpreadMulti;
     }
     StartCoroutine(turretTargetEnemy.UpdateTarget());
 }