Exemple #1
0
    // Use this for initialization
    void Start()
    {
        speedOffset = Random.Range(5, 30);



        lG = laser.GetComponent <LaserGun>();
        lG.setStats(5f, 8f, 5f, 0.5f);
        foreach (Transform child in transform)
        {
            // do whatever you want with child transform object here
            if (child.name == "LaserGun")
            {
                laser = child;
            }
        }
        lG.fire();
        //sF = gameObject.GetComponent<SmoothFollow>();
        //sF.enabled = false;
        isTeleported = false;
        isVenting    = false;
        hasExploded  = false;

        /*
         * GameObject.Instantiate(spawnOutline, new Vector3(transform.position.x,
         *                                                                                               transform.position.y,
         *                                                                                               transform.position.z), Quaternion.identity);
         */
    }
Exemple #2
0
    void fireLasers()
    {
        GameObject    sM     = GameObject.Find("ScreenManager");
        ScreenManager script = sM.GetComponent <ScreenManager>();

        if (script.currentScreen == 2)
        {
            int currentWeapon = PlayerPrefs.GetInt("CurrentWeapon");

            if (currentWeapon == 3)               // laser
            {
                LaserGun lG = laser.GetComponent <LaserGun>();
                //lG.setStats((float)PlayerPrefs.GetInt("W1Damage") * 3, (float)PlayerPrefs.GetInt("W1Range"), LaserFireRate - fireRateMod, 0.5f);
                lG.mute = true;
                lG.fire();

                NextFireAt = Time.time + LaserFireRate - fireRateMod;

                //GameObject.Instantiate(laser, transform.position, Quaternion.identity);
                //NextFireAt = Time.time + LaserFireRate -  fireRateMod;
            }

            if (currentWeapon == 1)               // scatter
            {
                GameObject.Instantiate(tripleShot, transform.position, Quaternion.identity);
                NextFireAt = Time.time + TripleFireRate - fireRateMod;
            }

            if (currentWeapon == 2)               // melee
            {
                GameObject.Instantiate(melee, transform.position, Quaternion.identity);
                NextFireAt = Time.time + MeleeFireRate - fireRateMod;
            }

            if (currentWeapon == 4)
            {
                GameObject.Instantiate(mortarShot, transform.position, Quaternion.identity);
                NextFireAt = Time.time - fireRateMod;
            }
        }
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        tk2dSprite mySprite = gameObject.GetComponent <tk2dSprite>();

        //	mySprite.color += new Color(255,255,255, amt);

        // enable movement once teleported in
        if (mySprite.color.a >= 0.75f)
        {
            //sF.enabled = true;
            isTeleported = true;
        }
        if (isTeleported)
        {
            GameObject pl;
            pl = GameObject.Find("Player1(Clone)");

            //Vector3 targetDir = pl.transform.position - laser.transform.position;
            //float distance = targetDir.magnitude;
            //Vector3 forward = laser.transform.forward;
            //float angle = Vector3.Angle(targetDir, forward);
            //Vector3 direction = targetDir/distance;
            //laser.transform.Rotate (new Vector3(0, 0, angle));
            //laser.transform.LookAt (pl.transform.position);
            //laser.transform.Rotate (new Vector3 (0, -90, 0));
            //laser.transform.rotation = Quaternion.Lerp(laser.transform.rotation, Quaternion.Euler(direction), Time.deltaTime * 1f);
            //Vector3 forward = lG.transform.forward;
            //float angle = Vector3.Angle(targetDir, forward);



            laser.transform.Rotate(0, 0, Time.deltaTime * speedOffset);

            //laser.transform.eulerAngles = new Vector3(0, 0, angle);
            if (lG.status == 0)
            {
                //laser.LookAt(pl.transform);
                lG.fire();
            }
        }
    }
Exemple #4
0
    void Update()
    {
        var facingRadian    = (float)(transform.rotation.eulerAngles.z / 180 * Math.PI);
        var facingDirection = new Vector2(Mathf.Cos(facingRadian), Mathf.Sin(facingRadian));

        if (Input.GetButton("Fire1"))
        {
            // Note laser's path is determined at the start of the shooting
            // to prevent "scrubbing" cheats
            laserGun.fire(facingDirection);
        }

        // Fire Turret
        if (Input.GetKeyDown("space"))
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, facingDirection);
            turret.enabled            = true;
            turret.renderer.enabled   = true;
            turret.transform.position = hit.point - facingDirection * 0.01f;              // Slightly in front of wall
        }
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        //mySprite.color.a += .1f;

        // controls
        if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
        {
            if (transform.position.x <= -50)
            {
                transform.position = new Vector3(-50, transform.position.y, transform.position.z);
            }
            if (transform.position.x >= 50)
            {
                transform.position = new Vector3(50, transform.position.y, transform.position.z);
            }
            if (transform.position.y <= -25)
            {
                transform.position = new Vector3(transform.position.x, -25, transform.position.z);
            }
            if (transform.position.y >= 25)
            {
                transform.position = new Vector3(transform.position.x, 25, transform.position.z);
            }


            dir.x = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
            dir.y = Input.GetAxis("Vertical") * speed * Time.deltaTime;
            transform.position += dir;

            thruster.particleSystem.enableEmission = true;             // turn ON thrusters
        }
        else
        {
            thruster.particleSystem.enableEmission = false;             // turn OFF thrusters
        }

        // which direction to spin?
        if (!Input.GetKey(KeyCode.Space))
        {
            if (!Input.GetButton("joystick button 1"))
            {
                //if (!Input.GetButton("joystick button 1")) {
                if (dir.x > 0)
                {
                    lastDir = 0;
                }
                else if (dir.x < 0)
                {
                    lastDir = 1;
                }
            }


            //}
        }

        if (Input.GetKey(KeyCode.Space) || Input.GetButton("joystick button 1"))
        {
            if (restartMode)
            {
                //screenManager.currentScreen = 2;
                levelLogic.killWave();
                //levelLogic.reset();
                isRestarting = false;
                screenManager.resetGame();

                levelLogic.enableTimer();
                //levelLogic.killWave();
                //levelLogic.restartLevel();
                //levelLogic.enableTimer();

                restartMode  = false;
                isRestarting = false;


                if (gameObject != null)
                {
                    Destroy(gameObject);
                }

                levelLogic.killWave();
            }
        }

        if (lastDir == 0)
        {
            endingRotation     = Quaternion.Euler(new Vector3(0, 0, 0));         // rotate right
            transform.rotation = Quaternion.Lerp(transform.rotation, endingRotation, Time.deltaTime * rotationSpeed);
        }
        else if (lastDir == 1)
        {
            endingRotation     = Quaternion.Euler(new Vector3(0, -180, 0));         // rotate left
            transform.rotation = Quaternion.Lerp(transform.rotation, endingRotation, Time.deltaTime * rotationSpeed);
        }


        // weapons
        if ((Input.GetKey(KeyCode.Space) || Input.GetButton("joystick button 1")) && !restartMode && !isDead)
        {
            if (Time.time >= NextFireAt)              // if the cooldown has been reached
            {
                AudioSource.PlayClipAtPoint(playerFireSound, transform.position);

                if (currentWeapon == 3)                   // laser

                {
                    LaserGun lG = laser.GetComponent <LaserGun>();

                    lG.fire();

                    NextFireAt = Time.time + LaserFireRate - fireRateMod;
                }

                if (currentWeapon == 1)                   // scatter
                {
                    GameObject.Instantiate(tripleShot, laserSpawn.transform.position, Quaternion.identity);
                    NextFireAt = Time.time + TripleFireRate - fireRateMod;
                }

                if (currentWeapon == 2)                   // melee
                {
                    GameObject.Instantiate(melee, laserSpawn.transform.position, Quaternion.identity);
                    NextFireAt = Time.time + MeleeFireRate - fireRateMod;
                }
                if (currentWeapon == 4)                   // mortar
                {
                    GameObject.Instantiate(mortarShot, laserSpawn.transform.position, Quaternion.identity);

                    NextFireAt = Time.time + MeleeFireRate - fireRateMod;
                }
            }
        }
        else if ((Input.GetKeyDown(KeyCode.Backspace) || Input.GetButton("joystick button 2")) && restartMode == true)
        {
            stopRestartTimer();

            screenManager.currentScreen = 2;

            isRestarting = false;

            restartMode = false;


            if (gameObject != null)
            {
                Destroy(gameObject);
            }

            levelLogic.killWave();
        }


        // are we dead yet?
        if (isDead)
        {
            transform.renderer.enabled             = false;
            thruster.particleSystem.enableEmission = false;             // turn OFF thrusterss


            restartTimer -= Time.deltaTime;
            isRestarting  = true;
            //pauseRestartTimer();

            //restartMode = true;
            if (restartTimer < 0)
            {
                Debug.Log("timer reached!");
                stopRestartTimer();
                //pauseRestartTimer();
                //pauseRestartTimer();
            }
        }
        else
        {
            transform.renderer.enabled = true;
        }


        // render the health bar
    }