コード例 #1
0
    // ■最初に1回だけ実行する処理
    public void Start()
    {
        charaCon = GetComponent <CharacterController>(); // キャラクターコントローラーのコンポーネントを参照する
        animCon  = GetComponent <Animator>();            // アニメーターのコンポーネントを参照する
        //走るアニメーションを開始
        //this.animCon.SetFloat("Speed", 1);
        //Rigidbodyコンポーネントを取得
        this.rigicon = GetComponent <Rigidbody>();
        RivalController rivalController = GetComponent <RivalController>();

        audioSource = gameObject.GetComponent <AudioSource>();
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //创建敌人
        if (detectors.Count != 0)
        {
            foreach (GameObject obj in detectors)
            {
                if (!obj.activeSelf)
                {
                    deletes.AddLast(obj);
                }
            }
            foreach (GameObject obj in deletes)
            {
                detectors.Remove(obj);
                GameObject.Destroy(obj);
            }
            foreach (GameObject obj in detectors)
            {
                GameObject rival = Instantiate(rivalPrefab, new Vector3(obj.transform.position.x, rivalPrefab.transform.position.y, obj.transform.position.z), Quaternion.identity);
                rival.transform.Rotate(0f, Random.Range(-180f, 180f), 0f, Space.Self);
                rivalList.AddLast(rival);

                RivalController controller = rival.GetComponent <RivalController>();
                controller.DelegateDie(new DieCallback(OnRivalDie));
                controller.id = idNext;
                ++idNext;

                GameObject.Destroy(obj);
                ++completeNum;
            }
            detectors.Clear();
            deletes.Clear();
        }

        //询问服务器是否需新创建敌人
        if (isCreateOver && createRivalNum <= 0 && isRecv)
        {
            StartCoroutine("ResetRecv");
            byteBuilder.Add(System.BitConverter.GetBytes(Network.RIVAL_NUM));
            byteBuilder.Add(System.BitConverter.GetBytes(rivalList.Count));
            Global.network.Send(byteBuilder.GetByes());
            byteBuilder.Clear();
            isRecv = false;
        }
        else if (!isCreateOver && requestNum == createRivalNum) //检查是否创建成功
        {
            createRivalNum = requestNum - completeNum;
            //开始将未创建成功的创建
            for (int i = 0; i < createRivalNum; ++i)
            {
                CreateDetector();
            }
            requestNum  = 0;
            completeNum = 0;
        }

        if (!isCreateOver && createRivalNum <= 0)    //检查是否全部创建完成
        {
            completeNum    = 0;
            requestNum     = 0;
            createRivalNum = 0;
            isCreateOver   = true;
        }

        if (isCreateOver && createRivalNum > 0)  //检查是否有待创建的敌人
        {
            //开始将未创建成功的创建
            for (int i = 0; i < createRivalNum; ++i)
            {
                CreateDetector();
            }
            isCreateOver = false;
            requestNum   = 0;
            completeNum  = 0;
        }
    }