Example #1
0
 void OnEnable()
 {
     if (target == null)
     {
         return;
     }
     turret = target as F3DTurret;
 }
        /// <summary>
        /// Installs controller of turret
        /// </summary>
        void InstallTurretController()
        {
            F3DTurret turretController = this.gameObject.GetComponent <F3DTurret>();

            if (turretController == null)
            {
                F3DTurret[] turretControllers = this.gameObject.GetComponentsInChildren <F3DTurret>();
                int         i;
                for (i = 0; i < turretControllers.Length; i++)
                {
                    if (turretControllers[i] != null)
                    {
                        turretControllers[i].destroyIt = true;
                    }
                }

                F3DTurret newScript = this.gameObject.AddComponent <F3DTurret>();
                newScript.smoothControlling      = true;
                newScript.HeadingLimit.x         = -60f;
                newScript.HeadingLimit.y         = 60;
                newScript.ElevationLimit.x       = -60f;
                newScript.ElevationLimit.y       = 60f;
                newScript.ElevationTrackingSpeed = 30f;
                newScript.HeadingTrackingSpeed   = 30f;

                string[] namesMount = new string[] { "MOUNT", "Mount" };
                newScript.Mount = FindGameObject(namesMount, this.gameObject);
                string[] namesSwivel = new string[] { "SWIVEL", "Swivel" };
                newScript.Swivel = FindGameObject(namesSwivel, this.gameObject);
            }
            else if (turretController.Swivel == null || turretController.Mount == null)
            {
                string[] namesMount = new string[] { "MOUNT", "Mount" };
                turretController.Mount = FindGameObject(namesMount, this.gameObject);
                string[] namesSwivel = new string[] { "SWIVEL", "Swivel" };
                turretController.Swivel = FindGameObject(namesSwivel, this.gameObject);
            }
        }