コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 pos    = transform.localPosition;
        Vector3 camPos = mainCamera.transform.localPosition + new Vector3(0.5f, 0, 0);

        float dist = Vector3.Distance(pos, camPos);

//		print ("FB dist="+dist);
        if (dist < 0.1f)
        {
            mainCameraScript.setFireball(false);
        }

        pos.x -= speed;
        transform.localPosition = pos;

        distMoved += speed;

        if (distMoved > 30)
        {
            Destroy(gameObject);
        }
    }
コード例 #2
0
    IEnumerator fireballAttack(bool hint)
    {
        mainCameraScript.setFireball(true);
        yield return(StartCoroutine(mainCameraScript.rotateTo(0, 90, 0, 30)));

        if (hint)
        {
            mbText.text = "Use SWITCH to dodge fireballs, or burn!";
            messageBox.SetActive(true);
            pressedOK = false;
            while (!pressedOK)
            {
                yield return(null);
            }
            messageBox.SetActive(false);
        }

        controls.SetActive(true);

        for (int j = 0; j < nWavesFB; j++)
        {
            for (int i = 0; i < nPerWaveFB; i++)
            {
                if (!mainCameraScript.getFireball())
                {
                    yield break;
                }

                GameObject fb = Instantiate(fireballPrefab) as GameObject;
                fb.transform.parent = train.transform;

                float r = Random.value;

                float z;
                if (r < 0.5f)
                {
                    z = camTrainDisp.z;
                }
                else
                {
                    z = -camTrainDisp.z;
                }

                fb.transform.localPosition = new Vector3(mainCamera.transform.localPosition.x + tunnelLength / 2, 0, z);
                yield return(new WaitForSeconds(delayFB));
            }
            yield return(new WaitForSeconds(delayWavesFB));
        }

        if (mainCamera.transform.localPosition.z > 0)
        {
            yield return(StartCoroutine(mainCameraScript.rotateTo(0, 0, 0, 30)));
        }
        else
        {
            yield return(StartCoroutine(mainCameraScript.rotateTo(0, 180, 0, 30)));
        }

        mainCameraScript.setFireball(false);
        survivedFB = true;
    }