Hello , I’m trying to make a typing game ( like guitar hero but with letter from the keyboard)
I’ve made sprites representing each Letter ( say A has a sprite A )
i made a spawner and for each letter i made a fly script that makes the Letter fly towards our hero.
Now i put an aiming point to which when the Prefab( A ) hits the Aim and you press A on the keyboard . the Prefab gets destroyed and gives me a score…
here is my script
public class fly : MonoBehaviour {
score sc;
public Rigidbody2D flyingobj;
public float speed = -7f;
// Use this for initialization
void OnTriggerStay2D(Collider2D other)
{
if (other.tag == "aim" && Input.GetKeyDown(KeyCode.A))
{
sc = GameObject.Find("MainCamera").GetComponent<score>();
sc.IncreaseScore(2);
Destroy(this.gameObject);
}
}
void Start ()
{
// Set the prop's velocity to this speed in the x axis.
flyingobj.velocity = new Vector2(speed, 0);
}
// Update is called once per frame
void Update () {
}
}
okay now the problem is that I have 26 letters … that means i have to make a script for each letter … is there a way to make a generic script and then for each prefab bind it to a key input?
like say
{
if (other.tag == "aim" && Input.GetKeyDown(KeyCode.(generic)))
}
and generic is A in the A prefab…
[I know that this code is wrong , i’m just trying to explain myself]
Or is there an easier way to do this?
Thank you for your time!
PS : if you haven’t noticed already I’m a beginner in Unity and scripting all together I’m learning as i go