Quantcast
Viewing latest article 13
Browse Latest Browse All 81

Footstepsound choosing with less if else code?

this is more a question (is this possible and is this faster to execute for unity) I am making a first person scary horror game. I have a script in my game for the headbobbing so that the camera goes left right up and down when you walk. this script will send every time the player makes a step the "var doStep" to my (FootstepAudio_Controller). now in my FootstepAudio_Controller I have a class that contains many many arrays of AudioClips for every material the player walks on. the script is not finished but I let a spherecast detect the flag of the ground. I want to know if there is a possible way to create less if else statements. because If I would do this for every material It would be a long script and it would probably be slower executed because of the many lines of code. like if one of the variables in the class == the physics.spherecast.hit.flag choose that sound array. if null set default or else set default. I hope you understand what I mean... here is my script I have coded so far. thanks for any help. @script RequireComponent(AudioSource) private var ch : CharacterController; private var motor : PlayerMotor_harry; private var player : GameObject; private var sBM_v : SmoothBobbingMotion_velocity; var doStep : boolean; // get it from SmoothBobbingMotion_velocity script. class FootstepAudioCollection { var concrete : AudioClip[]; var wood : AudioClip[]; var woodPanels : AudioClip[]; var woodPanelCreak : AudioClip[]; var woodStairs : AudioClip[]; var woodLadder : AudioClip[]; var tiles : AudioClip[]; var tileShards : AudioClip[]; var carpet : AudioClip[]; var carpetStairs : AudioClip[]; var grass : AudioClip[]; var dirt : AudioClip[]; var puddle : AudioClip[]; var wade : AudioClip[]; var slosh : AudioClip[]; var mud : AudioClip[]; var paper : AudioClip[]; var leaves : AudioClip[]; var rock : AudioClip[]; var gravel : AudioClip[]; var sand : AudioClip[]; var metal : AudioClip[]; var metalLadder : AudioClip[]; var glassShards : AudioClip[]; var garbage : AudioClip[]; } var FSAudioMaterials : FootstepAudioCollection = FootstepAudioCollection(); function Awake() { ch = transform.parent.GetComponent(CharacterController); player = GameObject.Find("Player Body"); } function Update() { var chHNow = ch.height; transform.position.y = player.transform.position.y - (chHNow/2); }

Viewing latest article 13
Browse Latest Browse All 81

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>