public void Generate()
    {
        // 冷却中不会生成
        if (valid == false)
        {
            //Debug.Log("Cool time:" + Time.time);
            return;
        }

        // 求出位置/角度
        Vector3 vec = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        vec += pos.x * transform.right;
        vec += pos.y * transform.up;
        vec += pos.z * transform.forward;
        Quaternion rot = Quaternion.Euler(transform.eulerAngles);
        // 生成
        GameObject newObj = Object.Instantiate(target, vec, rot) as GameObject;

        // 设置父对象
        newObj.transform.parent = parentObj.transform;

        // 设置拥有者对象
        TorpedoCollider torpedoCollider = newObj.GetComponent <TorpedoCollider>();

        if (torpedoCollider)
        {
            torpedoCollider.SetOwner(type);
        }
        else
        {
            Debug.LogError("Not exists TorpedoCollider");
        }
        // 设置速度
        TorpedoBehavior torpedoBehavior = newObj.GetComponent <TorpedoBehavior>();

        if (torpedoBehavior)
        {
            torpedoBehavior.SetSpeed(speed);
        }
        else
        {
            Debug.LogError("Not exists TorpedoBehavior");
        }
        // 设置声音
        Note note = newObj.GetComponentInChildren <Note>();

        if (note)
        {
            note.SetEnable(sound);
        }
        else
        {
            Debug.LogError("Not exists Note");
        }
        // 设置声纳
        parentObj.SendMessage("OnInstantiatedChild", newObj);
        if (sonar)
        {
            newObj.BroadcastMessage("OnActiveSonar");
        }


        // 开始冷却
        valid   = false;
        current = 0.0f;
    }
Пример #2
0
    public void Generate()
    {
        // クールタイム中は生成しない.
        if (valid == false)
        {
            //Debug.Log("Cool time:" + Time.time);
            return;
        }

        // 位置・角度を求める.
        Vector3 vec = new Vector3(transform.position.x, transform.position.y, transform.position.z);

        vec += pos.x * transform.right;
        vec += pos.y * transform.up;
        vec += pos.z * transform.forward;
        Quaternion rot = Quaternion.Euler(transform.eulerAngles);
        // 生成.
        GameObject newObj = Object.Instantiate(target, vec, rot) as GameObject;

        // 親を設定.
        newObj.transform.parent = parentObj.transform;

        // オーナー設定.
        TorpedoCollider torpedoCollider = newObj.GetComponent <TorpedoCollider>();

        if (torpedoCollider)
        {
            torpedoCollider.SetOwner(type);
        }
        else
        {
            Debug.LogError("Not exists TorpedoCollider");
        }
        // スピードセット.
        TorpedoBehavior torpedoBehavior = newObj.GetComponent <TorpedoBehavior>();

        if (torpedoBehavior)
        {
            torpedoBehavior.SetSpeed(speed);
        }
        else
        {
            Debug.LogError("Not exists TorpedoBehavior");
        }
        // 音の設定.
        Note note = newObj.GetComponentInChildren <Note>();

        if (note)
        {
            note.SetEnable(sound);
        }
        else
        {
            Debug.LogError("Not exists Note");
        }
        // ソナーの設定.
        parentObj.SendMessage("OnInstantiatedChild", newObj);
        if (sonar)
        {
            newObj.BroadcastMessage("OnActiveSonar");
        }


        // クールタイム開始.
        valid   = false;
        current = 0.0f;
    }