Esempio n. 1
0
 /// <summary>
 /// Called each frame.
 /// </summary>
 void Update()
 {
     transform.position -= new Vector3(Movement.x * Time.deltaTime, 0, Movement.y * Time.deltaTime); // Generic movement
     HandleSpecialMovement();                                                                        // Enemy specific movement
     // Handle shooting
     if (WeaponKind != WeaponKinds.Unassigned)                                                       // Only when the weapon is assigned
     {
         Cooldown -= Time.deltaTime;
         if (Cooldown <= 0 && Camera.main.WorldToViewportPoint(transform.position).y > 0)
         {
             Projectile[] Projectiles = Shoot();
             for (int i = 0, c = Projectiles.Length; i < c; ++i)
             {
                 Projectiles[i].Damage     = Damage;
                 Projectiles[i].Speed      = 75;
                 Projectiles[i].WeaponKind = WeaponKind;
                 Projectiles[i].Repaint(WeaponBase.WeaponKindColor(WeaponKind));
             }
             if (!Source.Mute)
             {
                 Source.Play();
             }
             Cooldown += ShootingSpeed;
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Get the required source and pick a random clip to play it on.
        /// </summary>
        void Start()
        {
            AudioSource3D Source = GetComponent <AudioSource3D>();

            Source.clip = Clips[Random.Range(0, Clips.Length)];
            Source.Play();
        }
Esempio n. 3
0
 void OnEnable()
 {
     Source.Loop = true;
     Microphone.GetDeviceCaps(SourceName, out _, out int maxFreq);
     Source.clip      = Microphone.Start(SourceName, true, 1, maxFreq);
     Source.clip.name = SourceName;
     Source.Play();
 }
Esempio n. 4
0
        /// <summary>
        /// Play a sound at the location of a GameObject.
        /// </summary>
        /// <param name="Obj">Target</param>
        public static void PlaySoundOn(GameObject Obj)
        {
            GameObject NewObj = new GameObject();

            NewObj.transform.position = Obj.transform.position;
            AudioSource3D Source = NewObj.AddComponent <AudioSource3D>();

            Source.clip   = _SelectSound;
            Source.Volume = .1f;
            Source.Play();
            NewObj.AddComponent <TimedDespawner>().Timer = 1;
        }
Esempio n. 5
0
 void Update()
 {
     if (InitialTimeout > 0)
     {
         InitialTimeout -= Time.deltaTime;
         return;
     }
     if (Input.GetKeyDown(Skip) || !Settings.Music) // Trigger a skip by stopping the playback
     {
         Source.IsPlaying = false;
     }
     if (Settings.Music && !Source.IsPlaying)   // Play the next song if nothing is playing (either finished or interrupted)
     // Don't pick the same song again = exclude the last, and if the now playing is picked, use the last
     {
         int Pick = UnityEngine.Random.Range(0, Files.Length - Convert.ToInt32(Source.clip != null));
         if (Files[Pick].Clip == Source.clip)
         {
             Pick = Files.Length - 1;
         }
         // Disable music picker when files are missing
         if (!Files[Pick].Clip)
         {
             Debug.LogError("Music files are missing.");
             enabled = false;
             return;
         }
         // Get title
         Song = (Source.clip = Files[Pick].Clip).name;
         if (Song.Contains(" - "))
         {
             Artist = Song.Substring(0, Song.IndexOf(" - "));
             Song   = Song.Substring(Artist.Length + 3);
         }
         // Finalize
         Source.Volume = Files[Pick].Gain;
         DisplayTime   = 4;
         Source.Play();
     }
 }