This commit is contained in:
GungHolo
2023-06-24 13:58:30 +02:00
12 changed files with 708 additions and 517 deletions

View File

@@ -7,28 +7,49 @@ public class FallingDetection : MonoBehaviour
public bool isFalling;
private Animator animator;
public int counter = 0;
private bool wasFallingbefore = false;
private AudioSource audioSource; // Reference to the AudioSource component
public AudioClip landeSound; // The sound clip to be played
public AudioClip sprungSound; // The sound clip to be played
public bool isJumping = false;
private void Start()
{
animator = GetComponent<Animator>();
playerRigidbody = GetComponent<Rigidbody2D>();
charController = gameObject.GetComponent<CharController>();
audioSource = GetComponent<AudioSource>();
}
private void Update()
{
Vector3 velocity = playerRigidbody.velocity;
//Wenn nicht auf boden und geschwindigkeits offset pos
if (!charController.grounded && velocity.y > 0.1f && !isJumping){
audioSource.PlayOneShot(sprungSound);
isJumping = true;
}
if(charController.grounded){
isJumping = false;
}
//Wenn nicht auf boden und geschwindigkeits offset neg
if (!charController.grounded && velocity.y < -0.1f) {
//Wenn er bereits fällt, oder der counter erreicht ist zum fallen
if (isFalling || counter++>90) {
isFalling = true;
animator.SetBool("IsFalling", true);
counter = 0;
wasFallingbefore = true;
}
} else {
isFalling = false;
counter = 0;
animator.SetBool("IsFalling", false);
if(wasFallingbefore){
wasFallingbefore = false;
audioSource.PlayOneShot(landeSound);
}
}
}
}

View File

@@ -12,11 +12,15 @@ using UnityEngine;
public class InventoryBasic : MonoBehaviour
{
private LinkedList<GameObject> items;
private AudioSource audioSource; // Reference to the AudioSource component
public AudioClip keyTakeSound; // The sound clip to be played
public AudioClip doorOpenSound; // The sound clip to be played
// Start is called before the first frame update
void Start()
{
items = new LinkedList<GameObject>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
@@ -31,12 +35,14 @@ public class InventoryBasic : MonoBehaviour
case "Item":
other.gameObject.SetActive(false);
items.AddFirst(other.gameObject);
audioSource.PlayOneShot(keyTakeSound);
Debug.Log("Pickup: Take " + other.gameObject.name);
break;
case "Openable":
if (removeFirstOccurence("KEY"))
{
audioSource.PlayOneShot(doorOpenSound);
other.gameObject.SetActive(false);
Debug.Log("Pickup: Use Key");
}

View File

@@ -6,11 +6,16 @@ public class IsMovingTester : MonoBehaviour
{
private Animator animator;
private Rigidbody2D rb;
public AudioSource audioSource; // Reference to the AudioSource component
public AudioClip watschelSound; // The sound clip to be played
public bool isPlaying = false; // Boolean to control the sound loop
private FallingDetection fallingDetection;
void Start()
{
animator = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
fallingDetection = gameObject.GetComponent<FallingDetection>();
}
void Update()
@@ -18,10 +23,24 @@ public class IsMovingTester : MonoBehaviour
if (rb.velocity.magnitude > 0.1f)
{
animator.SetBool("IsMoving", true);
//Bewegt sich gerade und kein anderer Wert ist an, ausserdem Spielt es noch nicht
if (!animator.GetBool("IsPushing") && !animator.GetBool("IsFalling")&&!fallingDetection.isJumping){
if(!isPlaying){
audioSource.clip = watschelSound;
audioSource.loop = true;
audioSource.Play();
isPlaying = true;}
} else {
audioSource.Stop();
isPlaying = false;
}
}
else
{
animator.SetBool("IsMoving", false);
audioSource.Stop();
isPlaying = false;
}
}
}

View File

@@ -8,10 +8,13 @@ public GameObject door;
public SpriteRenderer spriteRenderer;
public Sprite originalSprite;
public Sprite activatedSprite;
public AudioSource audioSource; // Reference to the AudioSource component
public AudioClip buttonClickSound; // The sound clip to be played
private bool isActive = false;
// Start is called before the first frame update
void Start()
{
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
@@ -24,6 +27,10 @@ void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("PressurePlatable")){
door.SetActive(false);
spriteRenderer.sprite = activatedSprite;
if(!isActive){
audioSource.PlayOneShot(buttonClickSound);
isActive = true;
}
}
}

View File

@@ -5,14 +5,18 @@ using UnityEngine;
public class PlayerPressurePlateMod: MonoBehaviour
{
public SpriteRenderer spriteRenderer;
public SpriteRenderer spriteRenderer;
public Sprite originalSprite;
public Sprite activatedSprite;
public GameObject door;
public AudioSource audioSource; // Reference to the AudioSource component
public AudioClip buttonClickSound; // The sound clip to be played
public AudioClip doorOpenSound;
private bool isActive = false;
// Start is called before the first frame update
void Start()
{
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
@@ -26,6 +30,13 @@ void OnTriggerEnter2D(Collider2D other) {
// spriteRenderer.sprite = activatedSprite;
//}
spriteRenderer.sprite = activatedSprite;
if(!isActive){
audioSource.PlayOneShot(buttonClickSound);
audioSource.PlayOneShot(doorOpenSound);
isActive = true;
}
door.SetActive(false);
}