Exemple #1
0
    void createNewEnemy(int i, string type, float speed)
    {
        Random.seed = (int)System.DateTime.Now.Ticks;

        int param = Random.Range(0, 6);

        Vector3[] x = new Vector3[4];
        x[0] = new Vector3(9.9f, CurveMotion.getY(9.9f, type, param), 10);
        x[1] = new Vector3(-9.9f, CurveMotion.getY(-9.9f, type, param), 10);
        x[2] = new Vector3(CurveMotion.getX(9.9f, type, param), 9.9f, 10);
        x[3] = new Vector3(CurveMotion.getX(-9.9f, type, param), -9.9f, 10);



        for (int j = 0; j < x.Length; j++)
        {
            if ((!float.IsNaN(x[j].y)) && (!float.IsNaN(x[j].x)) &&
                Mathf.Abs(x[j].y) <= 11 && Mathf.Abs(x[j].x) <= 11)
            {
                enemies[i] = (GameObject)Instantiate(Resources.Load("Enemy"));
                enemies[i].transform.position = x[j];
                CurveMotion mEnemy = (CurveMotion)enemies[i].GetComponent(typeof(CurveMotion));
                mEnemy.functionType  = type;
                mEnemy.functionIndex = param;
                mEnemy.moveDirection = x[j].x > 0?-1:1;
                mEnemy.moveSpeed     = speed;
                SetProjectileColor(mEnemy);
                return;
            }
        }
    }
    void showTarget()
    {
        Vector3[] x = new Vector3[4];
        x[0] = new Vector3(9.9f, CurveMotion.getY(9.9f, currentFunction, currentInputLevel), 4);
        x[1] = new Vector3(-9.9f, CurveMotion.getY(-9.9f, currentFunction, currentInputLevel), 4);
        x[2] = new Vector3(CurveMotion.getX(9.9f, currentFunction, currentInputLevel), 9.9f, 4);
        x[3] = new Vector3(CurveMotion.getX(-9.9f, currentFunction, currentInputLevel), -9.9f, 4);

        int textureIndex = 0;

        switch (currentFunction)
        {
        case "linear":
            textureIndex = 0;
            break;

        case "quadratic":
            textureIndex = 1;
            break;

        case "exponential":
            textureIndex = 2;
            break;

        case "sinusoidal":
            textureIndex = 3;
            break;
        }
        for (int i = 0; i < x.Length; i++)
        {
            GameObject capsule = GameObject.Find("t" + i);
            if ((!float.IsNaN(x[i].y)) && (!float.IsNaN(x[i].x)) &&
                Mathf.Abs(x[i].y) <= 11 && Mathf.Abs(x[i].x) <= 11)
            {
                capsule.transform.position            = x[i];
                capsule.renderer.enabled              = true;
                capsule.renderer.material.mainTexture = targetTexture[textureIndex];
            }
            else
            {
                capsule.renderer.enabled = false;
            }
        }
        if (currentFunction == "quadratic")
        {
            if ((!float.IsNaN(x[2].y)) && (!float.IsNaN(x[2].x)) &&
                Mathf.Abs(x[2].y) <= 11 && Mathf.Abs(x[2].x) <= 11)
            {
                GameObject capsule = GameObject.Find("t" + 3);
                capsule.transform.position            = new Vector3(-x[2].x, x[2].y, x[2].z);
                capsule.renderer.enabled              = true;
                capsule.renderer.material.mainTexture = targetTexture[textureIndex];
            }
            else
            {
                GameObject capsule = GameObject.Find("t" + 2);
                capsule.transform.position            = new Vector3(-x[3].x, x[3].y, x[3].z);
                capsule.renderer.enabled              = true;
                capsule.renderer.material.mainTexture = targetTexture[textureIndex];
            }
        }
    }