-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfootSteps.cs
More file actions
64 lines (46 loc) · 1.62 KB
/
footSteps.cs
File metadata and controls
64 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class footSteps : MonoBehaviour
{
private AudioSource audioSource;
private GameObject terrainFoot;
private AudioSource terrainFootPrev;
private AudioSource terrainFootNext;
// LIST OF TERRAINS
public AudioSource footstepGrass; // 1
public AudioSource footstepFloor;
private void Start(){
terrainFootNext = terrainFootPrev = footstepGrass; // 0 - PLAYER STARTING TERRAIN
}
void Update()
{
audioSource = GetComponent<AudioSource>();
terrainFoot = FindObjectOfType<TerrainDetector>().PlayerTerrain();
if( Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) ||
Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D) )
{
switch(terrainFoot.name)
{
case "GRASS": // 2
footstepGrass.enabled = true; // 2
terrainFootPrev = footstepGrass; // 2
break;
case "floor":
footstepFloor.enabled = true;
terrainFootPrev = footstepFloor;
break;
default:
break;
}
if(terrainFootPrev != terrainFootNext)
{
terrainFootNext.enabled = false;
terrainFootNext = terrainFootPrev;
}
}else{
footstepGrass.enabled = false; // 3
footstepFloor.enabled = false;
}
}
}