HELP WITH TOUCH SCRIPT
Hi there,
I'm a little noob in Unity, right now I'm trying to make a guitar hero-like game for android. The thing is that I've got a good script to destroy the notes with a trigger (as they fall) but it is used with keys, and I'd like to trigger them with the touch. For example, when I touch the Circle on the screen just right when the note is getting to it I want it to destroy the note. Here is the script I'm using:
public KeyCode key;
bool active = false;
GameObject note;
SpriteRenderer sr;
Color old;
void Awake () {
sr = GetComponent<SpriteRenderer>();
}
private void Start()
{
old = sr.color;
}
void Update () {
if (Input.GetKeyDown(key))
StartCoroutine(Pressed());
if (Input.GetKeyDown(key) && active)
{
Destroy(note);
}
}
private void OnTriggerEnter2D(Collider2D col)
{
active = true;
if (col.gameObject.tag=="Note")
{
note = col.gameObject;
}
}
void OnTriggerExit2D(Collider2D col)
{
active = false;
}
IEnumerator Pressed()
{
sr.color = new Color(0,0,0);
yield return new WaitForSeconds(0.1F);
sr.color = old;
}
So I'd like that instead of getting the key to trigger the destroy. It's triggered after having touched the object that has got this script.
Thanks in advanced for your help. <3
Your answer
Follow this Question
Related Questions
OnTriggerEnter2D() does not work !!! 0 Answers
Making a mini copy of the objects around the player? 0 Answers
Lights shutting down with sound 1 Answer
Whenever my player lands a shot on the enemy they hurt themselves, help please >< 0 Answers
Need help coding collision detection to a destroy command. 0 Answers