public void TakeDamage(int amount, Vector3 hitPoint) { //if (isDead == true) //{ //return //} if (isDead) { return; //return hace que salgamos de la función y no sigamos mirando el resto de líneas de código } //curentHealth = currentHealth - amount; klAudioSource.SetFloatVar(klVar, 0); klAudioSource.Play(); ShowHitParticles(); currentHealth -= amount; //Habilitar partículas if (currentHealth <= 0) { Death(); } }
//Función que vamos a llamar desde el script de ataque del enemigo public void TakeDamage(int amount) { klAudioSource.SetFloatVar(krillVar, 1); klAudioSource.Play(); damaged = true; currentHealth -= amount; slider.value = currentHealth; if (currentHealth <= 0 && !isDead) { Death(); } }
public void Shoot() { timer = 0; //Reseteo el timer klAudioSource.Play(); gunLight.enabled = true; //habilito la luz lineRenderer.enabled = true; //habilito el line renderer lineRenderer.SetPosition(0, transform.position); //Configuración del raycast shootRay.origin = transform.position; shootRay.direction = transform.forward; if (Physics.Raycast(shootRay, out shootHit, range, shootableMask)) //Lanzamos el raycast { GameObject enemy = shootHit.collider.gameObject; //estoy cogiendo el gameobject con el que estoy chocando if (enemy.GetComponent <EnemyHealth>()) //¿este gameobject tiene el componente EnemyHealth? { enemy.GetComponent <EnemyHealth>().TakeDamage(damagePerShot, shootHit.point); lineRenderer.SetPosition(1, shootHit.point);//shootHit.point es el punto de impacto entre rayo y objeto } } else { //Segunda posición del lineRenderer cuando no hemos dado al enemigo lineRenderer.SetPosition(1, shootRay.origin + shootRay.direction * range); } }
private void DrawListElement(Rect rect, int index, bool isActive, bool isFocused) { rect.y += 2; var element = rList.serializedProperty.GetArrayElementAtIndex(index); float tw = rect.width; float buttonWidth = 45; GUI.enabled = !Application.isPlaying; EditorGUI.PropertyField(new Rect(rect.x, rect.y, tw - buttonWidth - 5, EditorGUIUtility.singleLineHeight), element, GUIContent.none); GUI.enabled = true; // Draw button if (Application.isPlaying) { GUI.backgroundColor = m_target.IsPlaying(index) ? Color.green : Color.white; if (GUI.Button(new Rect(rect.x + tw - buttonWidth, rect.y, buttonWidth, EditorGUIUtility.singleLineHeight), "Play")) { m_target.Play(index); } GUI.backgroundColor = Color.white; } else { if (GUI.Button(new Rect(rect.x + tw - buttonWidth, rect.y, buttonWidth, EditorGUIUtility.singleLineHeight), "Test")) { KLStartup.Logger.LogWarning(string.Format("<b>[KLAudioSourceEditor]</b> Test {0} tag is not implemented!", element.stringValue)); } } }