void Awake() { if (Instance != null) { Debug.LogError("Existem múltiplas instâncias do script SoundEffectScript."); } Instance = this; }
void Awake() { if (Instance != null) { Debug.LogError("Existem múltiplas instâncias do script SoundEffectScript."); } Instance = this; }
void Awake() { if (Instance != null) { Debug.LogError("Multiple instances of the SoundEffectScript script."); } Instance = this; }
public void Collect() { collected = true; velocity = velocityMax; GetComponent <CapsuleCollider>().enabled = false; if (collectSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, collectSound); } }
/// <summary> /// Static method to easily play a sound effect at the speficied location in world coordinates /// </summary> /// <param name="position">The world location at which to play the sound effect</param> /// <param name="clip">The sound clip to play</param> public static void PlaySoundEffect(Vector3 position, AudioClip clip) { GameObject soundObject = new GameObject("SoundEffect"); soundObject.transform.position = position; SoundEffectScript effect = soundObject.AddComponent <SoundEffectScript>(); effect.clip = clip; effect.Play(); }
void Awake() { // Register the singleton if (Instance != null) { Debug.LogError("Multiple instances of SoundEffectScript!"); } Instance = this; }
// Handle a hit to the killable object (only if it can currently be hit) public void Hit(int power) { // Cancel the whole function if the object can't be hit or the killablescript isn't active if (!canBeHit || !alive) { return; } // Disable hits to the object for a short time canBeHit = false; // If power requirement met, do damage based on attack power level (and power requirement functions as armor) if (power >= powerRequirement && health > 0) { health -= (power - (powerRequirement - 1)); } // Handle death or recovery if (health <= 0) { // Kill the killable object (with fancy particle effects provided by the generator) alive = false; if (polyParticleGenerator != null) { GameObject particleFX = Instantiate(polyParticleGenerator); particleFX.transform.position = transform.position; particleFX.transform.rotation = transform.rotation; } // Play the death sound if (deathSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, deathSound); } // If preserve isn't set, destroy the object completely if (!preserveAfterDeath) { Destroy(gameObject); } } else { // Not dead yet, so start recovery StartCoroutine(HitRecover()); // Play the hit sound if (hitSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, hitSound); } } }
void Start() { if (instance == null) { instance = this; CreateDictionary(); DontDestroyOnLoad(this); } else { Destroy(gameObject); } }
/// <summary> /// Kill the player with a death sound and a small splash of pixel blood /// </summary> public void Kill() { // TODO - visual death effects // Death sound effect if (deathSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, deathSound); } // Make a pixel blood splash effect for a dramatic death ParticleEffectScript.Splash(bloodParticlePrefab, transform, 25, 0.1f, 75.0f, 75.0f, 300.0f); // TODO - respawn player and reset level }
// Called at a fixed rate along with physics updates private void FixedUpdate() { // Jump movement if (Input.GetButtonDown("Jump") && grounded) { // TODO - apply jump movement if (jumpSound != null) { SoundEffectScript.PlaySoundEffect(transform.position, jumpSound); // Jumping sound effect } } // Horizontal movement moveVelocity.x += Input.GetAxis("Horizontal"); moveVelocity.x = Mathf.Clamp(moveVelocity.x, -speed, speed); // TODO - better movement // Set the animator parameters GetComponent <Animator>().SetBool("Grounded", grounded); GetComponent <Animator>().SetFloat("HVelocity", moveVelocity.x / speed); GetComponent <Animator>().SetFloat("VVelocity", moveVelocity.y / speed); }
void Start() { if (instance == null) { instance = this; CreateDictionary(); DontDestroyOnLoad(this); } else { Destroy(gameObject); } }