Commit 1168c5df authored by gstuitje's avatar gstuitje
Browse files

Can now skip to starting at different points in a song

parent 403ba606
<Properties StartupConfiguration="{67A4F128-F6AC-CD88-DA35-F29416A0792A}|">
<MonoDevelop.Ide.ItemProperties.Assembly-CSharp PreferredExecutionTarget="Unity.Editor" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/Scripts/SpawnKeys.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/Scripts/Key.cs">
<Files>
<File FileName="Assets/TextFiles/TestMultiples.txt" Line="1" Column="1" />
<File FileName="Assets/Scripts/SpawnKeys.cs" Line="9" Column="18" />
<File FileName="Assets/Scripts/SpawnKeys.cs" Line="60" Column="59" />
<File FileName="Assets/Scripts/Key.cs" Line="1" Column="1" />
<File FileName="Assets/Scripts/TriggerManager.cs" Line="1" Column="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
......
......@@ -36,7 +36,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1765769401102260}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 5, y: 4, z: 0}
m_LocalPosition: {x: 5, y: -3.994, z: 0}
m_LocalScale: {x: 1.6, y: 1.6, z: 1}
m_Children: []
m_Father: {fileID: 0}
......@@ -78,7 +78,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3ca1ceb8b7b7e47b0afcf424c76fb6a2, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 1
speed: 2
points: 10
--- !u!212 &212894587835513782
SpriteRenderer:
......
......@@ -6,7 +6,10 @@ public class SpawnKeys : MonoBehaviour {
public TextAsset songFile;
public GameObject arrowPrefab;
public float skip;
private string song = "default";
private float startTime;
Queue<string[]> songKeys = new Queue<string[]>();
string[] nextKey;
......@@ -15,7 +18,7 @@ public class SpawnKeys : MonoBehaviour {
float[] timings;
int pointer = 0;
float startTime;
float songWaitTime;
// Use this for initialization
void Start () {
......@@ -41,7 +44,8 @@ public class SpawnKeys : MonoBehaviour {
{
songKeys.Enqueue(line.Split(' '));
}else{
song = line;
song = line.Split(' ')[0];
songWaitTime = float.Parse(line.Split(' ')[1]);
}
count++;
}
......@@ -52,37 +56,50 @@ public class SpawnKeys : MonoBehaviour {
// string[] x = songKeys.Dequeue();
// print(x[0] + " " + x[1]);
//}
print(song);
print(Resources.Load("Bavaria"));
AudioClip songAudio = Resources.Load<AudioClip>(song);
AudioSource.PlayClipAtPoint(songAudio, transform.position);
songWaitTime = songWaitTime / arrowPrefab.GetComponent<Key>().speed;
StartCoroutine(playSong(songAudio, songWaitTime));
}
//plays the song after the first arrow reaches a barrier.
private IEnumerator playSong(AudioClip musicClip, float waitTime){
yield return new WaitForSeconds(waitTime);
AudioSource music = transform.GetComponent<AudioSource>();
music.clip = musicClip;
music.Play();
music.time = skip;
}
// Update is called once per frame
void Update () {
while (nextKey != null && Time.time > startTime + float.Parse(nextKey[1]))
while (nextKey != null && Time.time > startTime + float.Parse(nextKey[1]) - skip)
{
switch (nextKey[0])
{
case "left":
//print("left");
Instantiate(arrowPrefab, new Vector3(5f, 4f, 1f), Quaternion.identity);
break;
case "right":
//print("right");
Instantiate(arrowPrefab, new Vector3(8f, 4f, 1f), Quaternion.identity);
break;
case "up":
//print("up");
Instantiate(arrowPrefab, new Vector3(6f, 4f, 1f), Quaternion.identity);
break;
case "down":
//print("DOWN");
Instantiate(arrowPrefab, new Vector3(7f, 4f, 1f), Quaternion.identity);
break;
default:
break;
if (float.Parse(nextKey[1]) >= skip)
{
switch (nextKey[0])
{
case "left":
//print("left");
Instantiate(arrowPrefab, new Vector3(5f, 4f, 1f), Quaternion.identity);
break;
case "right":
//print("right");
Instantiate(arrowPrefab, new Vector3(8f, 4f, 1f), Quaternion.identity);
break;
case "up":
//print("up");
Instantiate(arrowPrefab, new Vector3(6f, 4f, 1f), Quaternion.identity);
break;
case "down":
//print("DOWN");
Instantiate(arrowPrefab, new Vector3(7f, 4f, 1f), Quaternion.identity);
break;
default:
break;
}
}
if (songKeys.Count > 0)
{
......
Bavaria
left 1
right 1.5
up 2.34
down 4.3
right 5.5
left 5.5
\ No newline at end of file
Bavaria 7.8
left 0
right 0.3
up 0.6
down 1.1
up 1.6
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment