示例#1
0
    private void SpawnAsteroidMain()
    {
        if (asteroidMain != null)
        {
            Destroy(asteroidMain);
        }
        //add necessary scripts for collision
        asteroidMain = Instantiate(asteroidMainPrefab, asteroidMainPosition, Quaternion.identity);
        asteroidMain.transform.localScale = asteroidSize;
        Rigidbody asteroidMainRigidBody = asteroidMain.AddComponent <Rigidbody>();

        asteroidMainRigidBody.useGravity = false;
        SphereCollider asteroidMainSphereCollider = asteroidMain.AddComponent <SphereCollider>();

        asteroidMainSphereCollider.radius = asteroidMainColliderRadious;
        StartExplosion asteroidStartExplosionComponent = asteroidMain.AddComponent <StartExplosion>();

        asteroidStartExplosionComponent.experimentController = gameObject.GetComponent <ExperimentController>();

        asteroidHasNotExploded      = true;
        asteroidMainPositionCurrent = asteroidMainPosition;
    }
    /* This function is called once per frame and is used to
     * update the game
     */
    void FixedUpdate()
    {
        initialX = transform.position.x;
        initialY = transform.position.y;
        rocketX  = transform.position.x;
        rocketY  = transform.position.y;
        rocketZ  = transform.position.z;

        //If the rocket is not in launch mode, keep it in a state of reset
        if (launch == false)
        {
            // Set the initial conditions for the launch
            Camera.reset();
            Skybox.reset();
            velocity = RocketState.fuel + 20;
            angleRad = (180 - RocketState.angle) * ((float)Math.PI) / 180;
        }

        // When the launchPad animation is done...
        if (LaunchPad.animationDone == true)
        {
            // Set the launch mode, play the particle system and rocket sounds
            GUISwitch.launch_mode();
            particleSyst.Play();
            smoke.Play();
            ScreenChanges.launch_sounds();
            LaunchPad.reset();
        }

        Vector3 rocket_direction = (transform.position - prevPos).normalized;

        // Handles moving rocket
        if (particleSyst.isPlaying)
        {
            // Change camera position and modify stars
            Camera.launchShift();
            stars.transform.forward = cam.forward;
            StartExplosion.Explode();

            // update position of rocket
            rocket_direction = (transform.position - prevPos).normalized;
            Vector3    input_angle_vector   = (new Vector3((float)Math.Cos(angleRad), (float)Math.Sin(angleRad), 0).normalized) * velocity;
            Quaternion input_angle_rotation = Quaternion.LookRotation(Vector3.forward, input_angle_vector);

            Vector3 move = transform.position;

            // Update the position based on the different parts of the launch sequence
            if (Math.Pow(gameTime, 3) < velocity || transform.position.y < LaunchPadHeight)
            {
                move = launchPhase_TakeOff();
            }
            else if (turning && Quaternion.Angle(transform.rotation, input_angle_rotation) > 5f)
            {
                move = launchPhase_TurnToAngle(input_angle_vector, input_angle_rotation);
            }
            else
            {
                move = launchPhase_PhysicsTrajectory(rocket_direction);
            }

            // Reorient the camera
            GameObject.Find("HUD").transform.forward = cam.forward;

            // update position variables
            prevPos            = transform.position;
            transform.position = move;

            // Check win/lose conditions
            check_win_lose(prevPos.y, transform.position.y);
        }

        // Handles dropping fuel pods - This incomplete functionality has been removed for the first release

        /*if ( (Input.GetKeyDown(KeyCode.Space)) ) {
         *      dropPod (rocket_direction);
         *      // Adjust the rockets trajectory if users drops fuel pod too early/late
         *      changeAngle (0,rocket_direction,turning);
         * }*/
    }