Quantcast
Channel: Latest Questions by f_rodrigues
Viewing all articles
Browse latest Browse all 18

Input/Output Good Pratice

$
0
0
I'm trying to separate user inputs, and it's respective outputs in order to avoid lot's of if(Input...) in my scripts. In the Player gameObject I set a script called UserInput, with the regular Update() "if(Input...)" and set all the user inputs, key presses, mouse movements there. Then I made a second Script called MasterOutput, which takes a input from the UserInput class(it varies depending on the input), then calls another static class depending on the Input. Eg: If the user press the Fire button: It will pass the Transform object and the mouse position then MasterOutput, which will call the Fire() class, and do what it haves to do. What I want to know, is that a good practice, or am I going for the wrong direction. I want to avoid clogging the Player GameObject with too many scripts and still be able to handle different kinds inputs. Also, I'm doing the passing like so: UserInput script: if(Input.GetButtonDown("Fire")){ new MasterOutput(gameObject,typeof(Fire)); MasterOutput script: public MasterOutput(GameObject go, System.Type action){ if (action == typeof(Fire)){ new Fire(go); } Fire Script: public Fire(GameObject player){ Object projectile = Resources.LoadAssetAtPath ("Assets/prefab/projectile.prefab",typeof(GameObject)); Instantiate(projectile,player.transform.position,player.transform.rotation); }

Viewing all articles
Browse latest Browse all 18

Trending Articles



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