コード例 #1
0
 // Use this for initialization
 void Start()
 {
     try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
     catch { Start(); }
     player.boosterAmmo--;
     Destroy(gameObject, 10.0f);
 }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
            catch { return; }
        }

        // make platform turn to the direction it is going to boost the player to
        if (player.facingRight)
        {
            transform.rotation = Quaternion.Euler(0, 0, -270f);
        }
        else
        {
            transform.rotation = Quaternion.Euler(0, 0, -90f);
        }

        // this experimental code makes the boost direction dependend on the position of the crosshair in relation to the player, the platform direction is adjusted accordingly
        // this type of booster platform could be used as an advanced upgrade to the standard booster
        if (directionalBoosterEnabled)
        {
            pos    = Camera.main.WorldToScreenPoint(transform.position);
            dir    = Input.mousePosition - pos;
            angle  = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
            angle += 90f;
            transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
    }
コード例 #3
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
            catch { return; }
        }
        if (exit == null)
        {
            exit = GameObject.FindGameObjectWithTag("ExitDoor").GetComponent <Exit> ();
            if (exit == null)
            {
                return;
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (exit.finished == true)
            {
                return;
            }
            if (pause == true)
            {
                pause = false;
                runGame();
            }
            else
            {
                pause = true;
                pauseGame();
            }
        }
    }
コード例 #4
0
    void OnTriggerEnter2D(Collider2D col)
    {
        SpaceMarineController player = col.GetComponent <SpaceMarineController>();

        // reload player ammo up until ammo limit is reached

        if (col.gameObject.tag == "Player")
        {
            if (platformPrefab.tag == "TrampolinePlatform")
            {
                player.trampolineAmmo += reloadAmount;
                if (player.trampolineAmmo > player.maxAmmo)
                {
                    player.trampolineAmmo = player.maxAmmo;
                }
            }
            if (platformPrefab.tag == "BoosterPlatform")
            {
                player.boosterAmmo += reloadAmount;
                if (player.boosterAmmo > player.maxAmmo)
                {
                    player.boosterAmmo = player.maxAmmo;
                }
            }

            player.PlayPickupSound();
            Destroy(gameObject);
        }
    }
コード例 #5
0
 // Update is called once per frame
 void Update()
 {
     if (player == null)
     {
         try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
         catch { return; }
     }
 }
コード例 #6
0
 // Use this for initialization
 void Start()
 {
     try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
     catch { Start(); }
     player.trampolineAmmo--;
     jumpCount = 0;
     Destroy(gameObject, 10.0f);
 }
コード例 #7
0
 // Update is called once per frame
 void Update()
 {
     if (player == null)
     {
         try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
         catch { return; }
     }
     if (finishMenu == null)
     {
         try{ finishMenu = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <FinishMenu> (); }
         catch { Debug.Log("FinishMenu not found!"); return; }
     }
 }
コード例 #8
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
            catch { return; }
        }

        if (exit == null)
        {
            try{ exit = GameObject.FindGameObjectWithTag("ExitDoor").GetComponent <Exit> (); }
            catch { return; }
        }

        if (Time.timeScale > 0 && !exit.finished)
        {
            direction = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
            rotationZ = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

            if (!player.facingRight)
            {
                rotationZ = -rotationZ;
            }
            if (direction.x >= 0)
            {
                transform.rotation = Quaternion.Euler(0f, 0f, rotationZ);
            }
            else
            {
                transform.rotation = Quaternion.Euler(0f, 0f, rotationZ + 180);
            }

            ls.x = x;
            transform.localScale = ls;

            if (direction.x >= 0 && !player.facingRight)
            {
                player.Flip();
                transform.rotation = Quaternion.LookRotation(Vector3.forward, Vector3.up);
            }
            else
            {
                if (direction.x < -0 && player.facingRight)
                {
                    player.Flip();
                    transform.rotation = Quaternion.LookRotation(Vector3.forward, Vector3.up);
                }
            }
        }
    }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
            catch { return; }
        }
        if (pauseMenu == null)
        {
            try{ pauseMenu = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <PauseMenu>(); }
            catch { return; }
        }
        if (exit == null)
        {
            try{ exit = GameObject.FindGameObjectWithTag("ExitDoor").GetComponent <Exit>(); }
            catch { return; }
        }

        if (!pauseMenu.pause && !exit.finished && !player.dying)
        {
            if (Input.GetButtonDown("Fire1"))
            {
                if (player.platformMode == 1)
                {
                    if (!cooldown)
                    {
                        cooldown = true;
                        Instantiate(projectilePrefab, transform.position, transform.rotation);
                        audio.PlayOneShot(projectileShotSound);
                        StartCoroutine(resetCooldown());
                    }
                }
                else if (player.platformMode == 2 && player.trampolineAmmo > 0)
                {
                    Instantiate(projectilePrefab, transform.position, transform.rotation);
                    audio.PlayOneShot(projectileShotSound);
                }
                else if (player.platformMode == 3 && player.boosterAmmo > 0)
                {
                    Instantiate(projectilePrefab, transform.position, transform.rotation);
                    audio.PlayOneShot(projectileShotSound);
                }
                else
                {
                    audio.PlayOneShot(outOfAmmoSound);
                }
            }
        }
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
            catch { return; }
        }

        // move projectile towards snapshotted cursor
        transform.position = Vector3.MoveTowards(transform.position, finalDestination, Time.deltaTime * 200);


        // instantiate the appropriate platform upon reaching destination
        if (finalDestination == transform.position)
        {
            switch (platformMode)
            {
            case 1:
                Instantiate(platformPrefab, transform.position, Quaternion.identity);
                break;

            case 2:
                if (player.trampolineAmmo > 0)
                {
                    Instantiate(trampolinePrefab, transform.position, Quaternion.identity);
                }
                break;

            case 3:
                if (player.boosterAmmo > 0)
                {
                    Instantiate(boosterPrefab, transform.position, Quaternion.Euler(0, 0, 90));
                }
                break;
            }
            Destroy(gameObject);
        }
    }
コード例 #11
0
    // Update is called once per frame
    void Update()
    {
        if (player == null)
        {
            try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
            catch { return; }
        }

        timeDisplay.text = player.timeAlive.ToString();

        trampolineAmmoDisplay.text = player.trampolineAmmo + "/" + player.maxAmmo;
        boosterAmmoDisplay.text    = player.boosterAmmo + "/" + player.maxAmmo;


        switch (player.platformMode)
        {
        case 1:
            standard.color   = standardColor;
            trampoline.color = Color.grey;
            booster.color    = Color.grey;
            break;

        case 2:
            standard.color   = Color.grey;
            trampoline.color = trampolineColor;
            booster.color    = Color.grey;
            break;

        case 3:
            standard.color   = Color.grey;
            trampoline.color = Color.grey;
            booster.color    = boosterColor;
            break;

        default:
            break;
        }
    }
コード例 #12
0
    void Start()
    {
        try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
        catch { Start(); }

        // snapshot player platformMode to spawn the choosen platform
        platformMode = player.platformMode;

        // make the projectile rotate to the cursor
        x                    = transform.localScale.x;
        ls                   = transform.localScale;
        direction            = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
        rotationZ            = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
        transform.rotation   = Quaternion.Euler(0f, 0f, rotationZ);
        ls.x                 = x;
        transform.localScale = ls;

        // snapshot cursor position so projectile doesn't change direction during flight
        finalDestination   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        finalDestination.z = 0;

        Destroy(gameObject, 2.0f);
    }
コード例 #13
0
 // Use this for initialization
 void Start()
 {
     try{ player = GameObject.FindGameObjectWithTag("Player").GetComponent <SpaceMarineController> (); }
     catch { Start(); }
 }