예제 #1
0
    void Throw(int i)
    {
        x   = Random.Range(-50f, 50f);
        y   = Random.Range(40f, 80f);
        z   = Random.Range(40f, 60f);
        dir = new Vector3(x, y, z);

        if (i >= ufosSpeed.Count)
        {
            ufosSpeed.Add(5);
        }

        ids.Add(UfoFactory.getInstance().getUfoId());
        ufos.Add(UfoFactory.getInstance().getUfo(ids[i]));
        ufos[i].transform.localScale *= scale;
        ufos[i].GetComponent <Renderer>().material.color = color;
        ufos[i].transform.position = new Vector3(pos.x, pos.y, pos.z + i * 2);
        ufos[i].SetActive(true);

        // 若是刚体模式, 则直接加一个力 (否则则在update上更新运动学动作)
        if (gameMode == true)
        {
            if (ufos[i].GetComponent <Rigidbody>() == null)
            {
                ufos[i].AddComponent <Rigidbody>();
            }

            ufos[i].GetComponent <Rigidbody>().mass        = 0.1f;
            ufos[i].GetComponent <Rigidbody>().drag        = 0.1f;
            ufos[i].GetComponent <Rigidbody>().angularDrag = 0.05f;
            //ufos[i].GetComponent<Rigidbody>().useGravity = true;
            ufos[i].GetComponent <Rigidbody>().AddForce(dir * Random.Range(speed * 5, speed * 10) / 10, ForceMode.Impulse);
        }
    }
예제 #2
0
    void Throw()
    {
        for (int i = 0; i < ufoNum; i++)
        {
            float x = Random.Range(-50f, 50f);
            float y = Random.Range(40f, 80f);
            float z = Random.Range(40f, 60f);
            dir = new Vector3(x, y, z);

            ids.Add(UfoFactory.getInstance().getUfoId());
            ufos.Add(UfoFactory.getInstance().getUfo(ids[i]));
            ufos[i].transform.localScale *= scale;
            ufos[i].GetComponent <Renderer>().material.color = color;
            ufos[i].transform.position = new Vector3(pos.x, pos.y, pos.z + i * 2);
            ufos[i].SetActive(true);
            ufos[i].GetComponent <Rigidbody>().AddForce(dir * Random.Range(speed * 5, speed * 10) / 10, ForceMode.Impulse);
        }
    }
예제 #3
0
 void Recycle(int i)
 {
     UfoFactory.getInstance().recycleUfo(ids[i]);
     ufos.RemoveAt(i);
     ids.RemoveAt(i);
 }
예제 #4
0
 void Awake()
 {
     UfoFactory.getInstance().ufoTemplate = UFO;
 }