示例#1
0
    void Update()
    {
        foreach (GameObject go in EnemiesManager.enemyShips)
        {
            if (go.transform.position.y < 4.5 && !startTime)
            {
                startTime = true;
                timer.Start();
            }

            double dist = Math.Sqrt((go.transform.position.x - ship.position.x) * (go.transform.position.x - ship.position.x) + (go.transform.position.y - ship.position.y) * (go.transform.position.y - ship.position.y));
            if (dist <= 1)
            {
                die();
                break;
            }
        }
        ship.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
        foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode)))
        {
            if (Input.GetKeyDown(vKey))
            {
                string key = vKey.ToString();
                key = key.ToLower();

                if (target == null)
                {
                    foreach (GameObject go in EnemiesManager.enemyShips)
                    {
                        if (key[0].Equals(go.GetComponentInChildren <TextMesh>().text[0]) && go.transform.position.y < 4.5)
                        {
                            Vector3 shotPos = ship.position;
                            shotPos.y += 0.5f;
                            target     = go;

                            TextMesh textmesh = target.GetComponentInChildren <TextMesh>();
                            textmesh.color = Color.yellow;

                            rotate();


                            GameObject shotObj = Instantiate(shot, shotPos, ship.rotation);

                            Destroy(shotObj, Vector3.Distance(shotObj.transform.position, go.transform.position) / 5);
                            correctStrokes++;
                            if (EnemiesManager.hit(go))
                            {
                                target = null;
                            }

                            break;
                        }
                    }
                }

                else if (key[0].Equals(target.GetComponentInChildren <TextMesh>().text[0]))
                {
                    correctStrokes++;
                    Vector3 shotPos = ship.position;
                    shotPos.y += 0.5f;
                    rotate();

                    TextMesh textmesh = target.GetComponentInChildren <TextMesh>();
                    textmesh.color = Color.yellow;

                    GameObject shotObj = Instantiate(shot, shotPos, ship.rotation);

                    Destroy(shotObj, Vector3.Distance(shotObj.transform.position, target.transform.position) / 5);

                    if (EnemiesManager.hit(target))
                    {
                        target = null;
                    }
                }
                totalStrokes++;
                avgWPM += wpm();
            }
        }
    }