예제 #1
0
    void ActionShip(shipState state)
    {
        switch (state)
        {
        case shipState.MOVINGUP:
            transform.Translate(0, speed * Time.deltaTime, 0, Space.World);
            break;

        case shipState.MOVINGDOWN:
            transform.Translate(0, speed * -Time.deltaTime, 0, Space.World);
            break;

        case shipState.MOVINGLEFT:
            transform.Translate(speed * -Time.deltaTime, 0, 0, Space.World);
            break;

        case shipState.MOVINGRIGHT:
            transform.Translate(speed * Time.deltaTime, 0, 0, Space.World);
            break;

        case shipState.SHOOT:
        {
            GameObject cloneLaser1 = Instantiate(laser, shootSpwnPos1.transform.position, shootSpwnPos1.transform.rotation) as GameObject;
            cloneLaser1.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.up * initialLaserSpeed);

            GameObject cloneLaser2 = Instantiate(laser, shootSpwnPos2.transform.position, shootSpwnPos2.transform.rotation) as GameObject;
            cloneLaser2.GetComponent <Rigidbody>().velocity = transform.TransformDirection(Vector3.up * initialLaserSpeed);
        }
        break;
        }
    }
예제 #2
0
    void ShipMovement()
    {
        if (Input.GetKey(KeyCode.Space))
        {
            if (fuelAmount > 0)
            {
                rb.AddForce(transform.up * enginePower);
                engineFire.SetActive(true);
                UseFuel();
            }
        }
        else
        {
            engineFire.SetActive(false);
        }

        h = Input.GetAxis("Horizontal");
        transform.Rotate(new Vector3(0, 0, -h * rotateSpeed * Time.deltaTime));


        if (Input.GetKeyDown(KeyCode.R))
        {
            if (currentShipState != shipState.antiDirMode)
            {
                currentShipState = shipState.antiDirMode;
            }
            else
            {
                currentShipState = shipState.freeMode;
            }
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            if (currentShipState != shipState.dirMode)
            {
                currentShipState = shipState.dirMode;
            }
            else
            {
                currentShipState = shipState.freeMode;
            }
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            this.GetComponent <Renderer> ().enabled = false;
            var pPosition = transform.position;
            StartCoroutine(destroyPlayer(pPosition));
        }

        if (playerDeathAnim != null)
        {
            if (!playerDeathAnim.GetComponent <Animation> ().IsPlaying("death"))
            {
                Destroy(playerDeathAnim);
                Destroy(this.gameObject);

                var script1 = gameMgObj.transform.gameObject.GetComponent <gameManager> ();
                script1.respawn      = true;
                script1.playerLives -= 1;
            }
        }

        if (shieldOn == true)
        {
            activateShield();
        }
        else
        {
            deActivateShield();
        }

        guiTime = Time.time - startTime;
        seconds = (int)(guiTime % 60);
        //print (seconds);
        if (seconds == 3)
        {
            playerInvincible = false;
            shieldOn         = false;
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            if (transform.position.y < 3.75)
            {
                curretnState = shipState.MOVINGUP;
                ActionShip(curretnState);
            }
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            if (transform.position.y > -3)
            {
                curretnState = shipState.MOVINGDOWN;
                ActionShip(curretnState);
            }
        }
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            if (transform.position.x > -2)
            {
                curretnState = shipState.MOVINGLEFT;
                ActionShip(curretnState);
            }
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            if (transform.position.x < 2)
            {
                curretnState = shipState.MOVINGRIGHT;
                ActionShip(curretnState);
            }
        }

        if (Input.GetKey(KeyCode.Space) && Time.time > nextFire)
        {
            nextFire     = Time.time + fireRate;
            curretnState = shipState.SHOOT;
            ActionShip(curretnState);
        }
    }