Skip to content

Commit

Permalink
Added sound, fixed colliders/player movement
Browse files Browse the repository at this point in the history
  • Loading branch information
cynrael committed Oct 9, 2018
1 parent 7798609 commit c3beb68
Show file tree
Hide file tree
Showing 16 changed files with 661 additions and 118 deletions.
30 changes: 30 additions & 0 deletions Freeway/Assets/Audio.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using UnityEngine.Audio;
using System;
using UnityEngine;

public class Audio : MonoBehaviour
{
public Sound[] sounds;

// Use this for initialization
void Awake () {

foreach (Sound s in sounds)
{
s.source = gameObject.AddComponent<AudioSource>();
s.source.clip = s.clip;

s.source.volume = s.volume;
s.source.pitch = s.pitch;

}

}

public void Play(string name)
{
Sound s = Array.Find(sounds, sound => sound.name == name);
s.source.Play();
}

}
11 changes: 11 additions & 0 deletions Freeway/Assets/Audio.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Freeway/Assets/Chicken1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public class Chicken1 : MonoBehaviour
public float speed;
public Text countText1;

private int count1;
private int y;
public int count1;

// Use this for initialization
void Start()
Expand All @@ -37,7 +36,9 @@ void OnCollisionEnter2D(Collision2D collisionInfo)
}
if (collisionInfo.gameObject.tag == "Car")
{
transform.position = new Vector2(4.15f, -7.15f);
transform.position = new Vector2(-4.15f, -5.765f);
FindObjectOfType<Audio>().Play("chiknscrem");

}
}

Expand Down
5 changes: 3 additions & 2 deletions Freeway/Assets/Chicken2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Chicken2 : MonoBehaviour
public float speed;
public Text countText2;

private int count2;
public int count2;

// Use this for initialization
void Start()
Expand All @@ -35,7 +35,8 @@ void OnCollisionEnter2D(Collision2D collisionInfo)
}
if (collisionInfo.gameObject.tag == "Car")
{
transform.position = new Vector2(4.15f, -7.15f);
transform.position = new Vector2(4.15f, -5.76f);
FindObjectOfType<Audio>().Play("chiknscrem");
}
}

Expand Down
Loading

0 comments on commit c3beb68

Please sign in to comment.