Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Space Shooter Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Mar 26, 2015.

  1. Jrradster2

    Jrradster2

    Joined:
    Nov 30, 2018
    Posts:
    1
    Hi I am using Unity version 2018.2.17f1 and I am trying to get the Score Text, Restart Text, and Game Over Text to display on screen when I use a GUI Text object. However, it doesn't show up and it says its obsolete. If this is the case, how do I get the text to appear. I have little experience so please be detailed if you answer. Thank you
     
  2. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    GUI Text seem doesn't work any more.Try using Canvas.(Hierarchy--Create--UI--Text).Remember to change the color or you will hardly see the text.
    At last I got the Score Text go properly in the game.
    Hope this can help!
     
  3. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    Hi,my Space Shooter project has run properly except one problem,the asteroids occasionally disappear when they drop.
    They disappear in different places before they reach the boundary.
    When I delete or disable the Boundary ,the asteroids go well and stop disappear.
    I have made the boundary bigger but the problem still here.How can I fix this?
     
  4. MaximumSpice

    MaximumSpice

    Joined:
    Oct 25, 2018
    Posts:
    22
    if anyone else gets stuck at the very end of the entire project with the Restart Button (in the extended learning videos) not work. read above. Drop Game Controller from your Hierarchy into on click, then in function click GameController and search for RestartGame ()

    Spent days on this very small problem. Unsure how/why it was left out in the live stream or maybe back then it wasn't needed to be done.
     
  5. doubledevwp

    doubledevwp

    Joined:
    Dec 7, 2018
    Posts:
    2
    Hello to all the people that have come across this issue, it has happened to me as well. I changed the scripts I was creating to mScriptName and that seemed to clear up the issue. I suspect that this has to do with having the same name in different Script folders.

    To Unity,
    I am working with Unity 2018.2.7f1 Personal working on Ubuntu 18.04.1 LTS and I am going through this tutorial. I am on the part to add the Audio (https://unity3d.com/learn/tutorials/projects/space-shooter-tutorial/audio?playlist=17147) and I can not drag and drop the audio files or reference them in any way, that I have found, to get this working. I attached some photos to show what I was doing.
     

    Attached Files:

  6. tpanavas

    tpanavas

    Joined:
    Dec 4, 2018
    Posts:
    1
    Thank you!!!!
     
  7. Chhaganlaal

    Chhaganlaal

    Joined:
    Dec 17, 2018
    Posts:
    5
    In the spawn waves tutorial why are we using the Start() and not any of the Update() or FixedUpdate()? Aren't we supposed to spawn the asteroids for different frames?
     
  8. Deleted User

    Deleted User

    Guest

    Try and modify the script and see what happens. :)
     
    Chhaganlaal likes this.
  9. the_rainbow_00

    the_rainbow_00

    Joined:
    Dec 19, 2018
    Posts:
    1
    I'm having trouble resetting my score back to 0 when "restart" is called. I have the same code as Wellfooled had.
     
  10. Chhaganlaal

    Chhaganlaal

    Joined:
    Dec 17, 2018
    Posts:
    5
    I started with the counting points tutorial but was unable to display the text through GUIText so I used the one with the canvas. But in the script what should I write instead of the GUI? And also what to do so that I can see the GUIText
     
  11. Chhaganlaal

    Chhaganlaal

    Joined:
    Dec 17, 2018
    Posts:
    5
    Tried it. So using Start() the StartCoroutine() is called once while with Update() it is called after every frame. So with Update() it looked like a lot of waves were spawned at once and they all collided with each other.
     
  12. tstavet

    tstavet

    Joined:
    Sep 29, 2018
    Posts:
    1
    In the script you can have a text variable like "public Text scoreText;" and assign it in the hierarchy. To change the text you just set the text of the variable with something like " scoreText.text = "Score: " + score;".

    As for being able to see the text, you move it around using the Rect Transform in the inspector for ScoreText . You can change the font using the text component in the inspector.

    That's what I did anyway, hope this helps!
    I figured this out using the Roll a Ball tutorial btw.
     
    Chhaganlaal likes this.
  13. Chhaganlaal

    Chhaganlaal

    Joined:
    Dec 17, 2018
    Posts:
    5
    So i completed the tutorial and everything worked fine in Unity but when i built the game and launched it in the browser for some reason I can't see the top part of the game i.e. the part with ScoreText and RestartText
     

    Attached Files:

    • SS1.PNG
      SS1.PNG
      File size:
      474.3 KB
      Views:
      779
    • SS2.PNG
      SS2.PNG
      File size:
      436.7 KB
      Views:
      779
  14. Chhaganlaal

    Chhaganlaal

    Joined:
    Dec 17, 2018
    Posts:
    5
    I want to add a help or info screen. Do I have to create a different scene for this?
     
    Last edited: Dec 26, 2018
  15. kiichii

    kiichii

    Joined:
    Dec 27, 2018
    Posts:
    5
    Hi, I can't seem to make enemy ship go down, they stuck at the top, and if an instance is placed, it only moves at the x axis, not on the z-axis.

    Space Shooter.jpg

    Game Controller Script

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class GameController : MonoBehaviour
    8. {
    9.  
    10.     public GameObject[] hazards; //Link reference to asteroid
    11.     public Vector3 spawnValues; //Vector input in editor for asteroid position
    12.     public int hazardCount; //Number of times asteroid will spawn
    13.     public float spawnWait; //Time in seconds to before next asteroid to appear
    14.     public float startWait; //Time in seconds for the player to prepare before asteroids to appear
    15.     public float waveWait; //Time in seconds for the player to wait for the next wave of asteroids
    16.  
    17.     public Text scoreText; //Reference to link the Text gameObject to GameController Script
    18.     private int score;
    19.  
    20.     public Text restartText;
    21.     public Text gameOverText;
    22.  
    23.     private bool restart; //This will help us track what the game is over and when it is okay to restart the game
    24.     private bool gameOver;
    25.  
    26.     void Start()
    27.     {
    28.         gameOverText.text = ""; //At start, game over is not written
    29.         restartText.text = ""; //At start, restart is not written
    30.         score = 0;
    31.         UpdateScore();
    32.         StartCoroutine (SpawnWaves());
    33.     }
    34.  
    35.     void Update()
    36.     {
    37.         if (restart)
    38.         {
    39.             if (Input.GetKeyDown(KeyCode.R))
    40.             {
    41.                 SceneManager.LoadSceneAsync("Main");
    42.             }
    43.         }
    44.     }
    45.  
    46.     IEnumerator SpawnWaves()
    47.     {
    48.         yield return new WaitForSeconds(startWait);
    49.         while (true) //The loop will remain until the condition is met, in this case, it is always true, so loop is infinite
    50.         {
    51.             for(int i = 0; i < hazardCount; i++) //In the declaration of the for loop, we need to initialise a counter, show the condition or state how long you want to stay in the loop, and then increment our counter.
    52.             {
    53.                 GameObject hazard = hazards[Random.Range(0, hazards.Length)];
    54.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    55.                 Quaternion spawnRotation = Quaternion.identity;
    56.                 Instantiate(hazard, spawnPosition, spawnRotation);
    57.                 yield return new WaitForSeconds(spawnWait);
    58.             }
    59.             yield return new WaitForSeconds(waveWait);
    60.        
    61.             if (gameOver)
    62.             {
    63.                 restartText.text = "Press 'R' for Restart";
    64.                 restart = true;
    65.                 break;
    66.             }
    67.         }
    68.     }
    69.  
    70.     public void AddScore (int newScoreValue) //Public function that can be used by other gameObject
    71.     {
    72.         score += newScoreValue;
    73.         UpdateScore();
    74.     }
    75.  
    76.     void UpdateScore()
    77.     {
    78.         scoreText.text = "Score: " + score;
    79.     }
    80.  
    81.     public void GameOver()
    82.     {
    83.         gameOverText.text = "Game Over!";
    84.         gameOver = true;
    85.     }
    86. }
    87.  
    EvasiveManeuver Script

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EvasiveManeuver : MonoBehaviour
    6. {
    7.     private float targetManeuver;
    8.     public float dodge;
    9.     public float smoothing;
    10.     private float currentSpeed;
    11.     public float tilt;
    12.  
    13.     public Vector2 startWait;
    14.     public Vector2 maneuverTime;
    15.     public Vector2 maneuverWait;
    16.     public Boundary boundary;
    17.  
    18.     private Rigidbody rb;
    19.  
    20.     void Start()
    21.     {
    22.         rb = GetComponent<Rigidbody>();
    23.         currentSpeed = rb.velocity.z;
    24.         StartCoroutine(Evade());  
    25.     }
    26.  
    27.     IEnumerator Evade()
    28.     {
    29.         yield return new WaitForSeconds(Random.Range(startWait.x, startWait.y));
    30.  
    31.         while (true)
    32.         {
    33.             targetManeuver = Random.Range(1, dodge) * -Mathf.Sign(transform.position.x);
    34.             yield return new WaitForSeconds(Random.Range(maneuverTime.x, maneuverTime.y));
    35.             targetManeuver = 0;
    36.             yield return new WaitForSeconds(Random.Range(maneuverWait.x, maneuverWait.y));
    37.         }
    38.     }
    39.  
    40.     void FixedUpdate()
    41.     {
    42.         float newManeuver = Mathf.MoveTowards(rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    43.         rb.velocity = new Vector3 (newManeuver, 0.0f, currentSpeed);
    44.         rb.position = new Vector3
    45.         (
    46.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    47.             0.0f,
    48.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    49.         );
    50.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    51.     }
    52. }
     
  16. Beepuu

    Beepuu

    Joined:
    Dec 22, 2018
    Posts:
    1
    Hi, do you have a "Mover" Script-Component assigned to your EnemyShip-Prefab?
     
  17. DoubleLKel

    DoubleLKel

    Joined:
    Dec 24, 2018
    Posts:
    1
    I've been having the same problem, and I'm noticing as well that the audio clips can't even be previewed. It seems the files are recognized as Audio (they have the right kind of Import Settings it seems), but these .wav files can't be loaded/played. I haven't tried with .mp3 instead, but I have tried in Windows, and the Windows editor successfully finds these files.

    Another website suggested installing the lib32stdc++6 library in Ubuntu, but I've had no luck. This is now in 2018.3.0f2.
     
    doubledevwp likes this.
  18. kiichii

    kiichii

    Joined:
    Dec 27, 2018
    Posts:
    5
    Hi, yes I do have that script.
    Here

    Space Shooter.1.jpg

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mover : MonoBehaviour
    6. {
    7.  
    8.     public float speed;
    9.  
    10.     private Rigidbody rb;
    11.  
    12.     // Start is called before the first frame update
    13.     //Want to move automatically when it's added to the scene, so use Start()
    14.     void Start()
    15.     {
    16.         rb = GetComponent<Rigidbody>();
    17.         rb.velocity = transform.forward * speed;
    18.     }
    19.  
    20. }
    21.  
    I feel like it has something to do white the velocity, but my previous post, the one with game controller script and maneuver, I think I didn't make any mistake. Or was it some settings that I don't know?
     
  19. doubledevwp

    doubledevwp

    Joined:
    Dec 7, 2018
    Posts:
    2
    I am glad that I am not the only one. Perhaps it is time for Unity to recreate the tutorials with these newer versions under Ubuntu :D
     
  20. egg_citizen

    egg_citizen

    Joined:
    Jan 3, 2019
    Posts:
    19
    I´m trying to start the first tutorial `01± Play _ Edit Mode.
    I´ve downloaded the course and chose Start in the Learn/hub.
    After that, I do get the `hold on..` screen in which stuff seems to be loaded in.
    Then, when Unity finally starts, at the bottom is the text `Exception generating network code: System.Exception: Assembly Temp\Unity.TextMeshPro.dll does not exist!

    What did I do wrong to get this message?

    Using Unity 2018.3.Of2
     
  21. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23
     
  22. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23
    You must remove the folder that is named Lobby.
    This was told earlier was something been added and unfortunate came out with the turtorial code if i remember correctly from an earlier message here.
     
    Last edited: Jan 13, 2019
    egg_citizen likes this.
  23. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23
    I also have a new problem.
    I have created a new larger asteroide by duplicate one of the others and made it larger.
    I also try to make it so that it need a few more S***s to break.

    At first everything looked OK until i hit it with the player ship. It plays the explosion and end the game but the ship is still there and can move around. Bolts also pass the new asteroid. but play the explosion. If i hit the small asteroides or the enemy ship it explode and die as normal.
    I tried a few attempts to make the harder to break hazard. Now i have created a copy of the DestroyOnContact with the routine for the new asteroide in it and only that attached to that asteroide.
    But now i also note that the enemy ship bolt does not harm the player.
    Under is the Code for the new asteroid XL

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. public class DestroyByContactXL : MonoBehaviour
    5. {
    6.     public GameObject explosion;
    7.     public GameObject playerExplosion;
    8.     public int scoreValue;
    9.     private GameController gameController;
    10.     private int Hitcount;
    11.     void Start()
    12.     {
    13.         GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");
    14.         if (gameControllerObject != null)
    15.         {
    16.             gameController = gameControllerObject.GetComponent<GameController>();
    17.         }
    18.         if (gameController == null)
    19.         {
    20.             Debug.Log("Cannot find 'GameController' script");
    21.         }
    22.     }
    23.     void OnTriggerEnter(Collider other)
    24.     {
    25.         if (other.tag == "Boundary" || other.tag == "Enemy" || other.tag == "AsteroideXL")
    26.         {
    27.             return;
    28.         }
    29.         if (explosion != null)
    30.         {
    31.             Instantiate(explosion, transform.position, transform.rotation);
    32.         }
    33.         if (other.tag == "Player")
    34.         {
    35.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    36.             gameController.GameOver();
    37.             Destroy(other);
    38.         }
    39.       //if (other.tag == "AsteroideXL") // || other.tag != "Player")
    40.      //   {
    41.             if (Hitcount < 3)
    42.             {
    43.                 Hitcount++;
    44.             }
    45.             else
    46.             {
    47.                 gameController.AddScore(scoreValue);
    48.                 Destroy(other.gameObject);
    49.                 Destroy(gameObject);
    50.             }
    51. {/CODE]
     
    Last edited: Jan 13, 2019
  24. egg_citizen

    egg_citizen

    Joined:
    Jan 3, 2019
    Posts:
    19
    I got it all to work eventually... though still not sure why. Tried a couple of things... my best bet would be, that it worked because now Unity is placed in the directory it sugggested while installing, instead of a directory of my choosing... but not sure (and not interested to trying that theory out :D). But thanks for thinking with me.
     
  25. Chachapoya

    Chachapoya

    Joined:
    Jan 14, 2019
    Posts:
    5
    Hey, when im shootting, i have 1 bolt rendering as 3.
    I guess its a matter of bolt speed and render speed but how to fix it ?
    (sidenote the game build setting is for pc,mac, linux)
     
  26. R3ps4c

    R3ps4c

    Joined:
    Jan 13, 2019
    Posts:
    5
    Hello. In the 3.02 part of the tutorial (Counting points and displaying the score), I'm having a problem when trying to assign the GameController instance to the Asteroid prefab (timecode 10:50):

    - I first select the Asteroid prefab from the Project and it opens in the Inspector but I have to click on the Open Prefab button to open it: Space Shooter prefab problem 1.png

    - When I click on it, it changes the Hierarchy and I don't have access to the GameController instance: Space Shooter prefab problem 2.png

    - So I try to click on the < button in the top-left of the Hierarchy but it empties the Inspector: Space Shooter prefab problem 3.png

    I can't attach the GameController to the Asteroid Prefab because of that. Does anyone know how to open the Prefab without changing the Hierarchy view? Or at least another way to attach an instance to a Prefab?
    I tried to attach it to an Asteroid instance and then drag that instance to the Assets to create a Prefab but it empties the GameController reference.

    It seems to be quite an important part of making games with Unity and without that, I'm in a dead end.
    By the way, I'm using Unity 2018.3.1f1.

    EDIT: O.K., I just paused the video too early. This part is just impossible but it's not meant to be done that way anyway, and the introduction of prefab editor in recent versions of Unity just makes it confusing with the tutorial.
     
    Last edited: Jan 17, 2019
  27. jeroennees

    jeroennees

    Joined:
    Jul 12, 2018
    Posts:
    5
    Hello,

    I'm sorry if this has been dicussed before, but I couldn't find it in this forum or upgrade manual:

    I'm using Unity 2018.3.1f1 in the tutorial at 2.05: "Spawning Waves"
    https://unity3d.com/learn/tutorials/projects/space-shooter/spawning-waves?playlist=17147

    After spawning multiple asteroids at the same time, using the for-loop, I sometimes get the error "Sub-emitters must be children of the system that spawns them". An instance of 'explosion-asteroid' is highlighted.

    I understand that it has something to do with the particle system.

    The error has some related bug-reports from Unity 2017.02 and later.

    What's a bit puzzling to me is that the error only appears on some plays, not always, although explosions are always instantiated. This makes me suspect it could be related to a bug.

    Has anyone had this and maybe found a cause, solution or workaround?

    Thanks!
     
  28. goldratte

    goldratte

    Joined:
    Jan 17, 2019
    Posts:
    1
    Hi,

    I'm having an issue with this part of the tutorial also; I cannot implement the "if (other.tag = "Boundary") { return;} function- Unity gives me a compiler error. The code looks identical to the one in the video, so must be connected to an Update- any help would be greatly appreciated!

    Here's the code I'm trying to use:

    public class DestroyByBoundary : MonoBehaviour
    {
    void OnTriggerExit(Collider other)
    {
    if (other.tag = "Boundary")
    {
    return;
    }
    Destroy(other.gameObject);
    Destroy(gameObject);
    }
    }

    I get the error message :Cannot implicitly convert 'string' to 'bool'
     
  29. jeroennees

    jeroennees

    Joined:
    Jul 12, 2018
    Posts:
    5
    I believe this is your issue: if (other.tag = "Boundary"): the equals sign should be double equals ('==') for comparing String values.
     
  30. lus-sco

    lus-sco

    Joined:
    Jan 18, 2019
    Posts:
    3
    The tutorial says to set the build target to WebPlayer, but it is not there in Unity 5.5.0f3. What should I set it to?
     
  31. jeroennees

    jeroennees

    Joined:
    Jul 12, 2018
    Posts:
    5
    I set it to WebGL..
     
  32. inferno523

    inferno523

    Joined:
    Jan 18, 2019
    Posts:
    1
    I get this error message and i cannot figure out why Here is my code. appreciate any help!
    NullReferenceException: Object reference not set to an instance of an object
    DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/DestroyByContact.cs:33)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class GameController : MonoBehaviour
    7. {
    8.     public GameObject hazard;
    9.     public Vector3 spawnValues;
    10.     public int hazardCount;
    11.     public float spawnWait;
    12.     public float startWait;
    13.     public float waveWait;
    14.     public Text scoreText;
    15.     public int score;
    16.     private void Start()
    17.     {
    18.         score = 0;
    19.         UpdateScore ();
    20.        StartCoroutine (spawnWaves());
    21.  
    22.     }
    23.     IEnumerator spawnWaves()
    24.     {
    25.         while (true)
    26.         {
    27.             for (int i = 0; i < hazardCount; i++)
    28.             {
    29.                 yield return new WaitForSeconds(startWait);
    30.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    31.                 Quaternion spawnRotation = Quaternion.identity;
    32.                 Instantiate(hazard, spawnPosition, spawnRotation);
    33.                 yield return new WaitForSeconds(spawnWait);
    34.             }
    35.             yield return new WaitForSeconds(waveWait);
    36.         }
    37.     }
    38.     public void AddScore (int newScoreValue)
    39.     {
    40.         score += newScoreValue;
    41.         UpdateScore();
    42.     }
    43.     void UpdateScore()
    44.     {
    45.         scoreText.text = "score " + score.ToString();
    46.     }
    47.  
    48. }
    49.  
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyByContact : MonoBehaviour
    6. {
    7.     public GameObject explosion;
    8.     public GameObject playerexplosion;
    9.     public int ScoreValue;
    10.     private GameController gameController;
    11.  
    12.     void start ()
    13.     {
    14.         GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    15.         gameController = gameControllerObject.GetComponent<GameController>();
    16.  
    17.         if (gameController == null) {
    18.             Debug.Log("Cannot Find 'GameController' script");
    19.         }
    20.     }
    21.  
    22.     private void OnTriggerEnter(Collider other)
    23.     {
    24.         if(other.tag == "Boundary")
    25.         {
    26.             return;
    27.         }
    28.         Instantiate(explosion, transform.position, transform.rotation);
    29.         if(other.tag == "Player")
    30.         {
    31.             Instantiate(playerexplosion, other.transform.position, other.transform.rotation);
    32.         }
    33.         gameController.AddScore (ScoreValue);
    34.         Destroy(other.gameObject);
    35.         Destroy(gameObject);
    36.     }
    37. }
    38.  
     
  33. jeroennees

    jeroennees

    Joined:
    Jul 12, 2018
    Posts:
    5
    gameController is probably null in line 33 because 'void start()' has lower case and is not executed, change to 'void Start()'. (shouldn't you get a compiler error in this case?)
    (edit: no error, but I did get a warning (C# in visual studio))
     
    Last edited: Jan 23, 2019
  34. antb1188

    antb1188

    Joined:
    Jan 20, 2019
    Posts:
    1
    Hi All,

    I had the issue where my bolt would not move. I went through the thread and didn't see a specific answer to the question, besides go back and check everything to the tutorial or finished scripts. When comparing the scripts because mover and playermover I noticed a difference between the start functions. I never actually got the rigid-body that was Instantiate. I have the change in bold, see below.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class mover : MonoBehaviour {
    public Rigidbody rb = new Rigidbody();
    public int speed;
    // Use this for initialization
    void Start () {
    rb = GetComponent<Rigidbody>();
    rb.velocity = rb.transform.forward * speed;
    }

    // Update is called once per frame
    void Update () {
    //rb.velocity = transform.forward*speed;
    }
    }

    This fixed my problem, I hope this helps you all.

    My Environment:
    Windows 10
    Unity 2017.3.0f3 Personal 64-bit
     
  35. Chachapoya

    Chachapoya

    Joined:
    Jan 14, 2019
    Posts:
    5
    btw
    there is a mistake on the unity 5 upgrade guide :

     
  36. SAPFIM

    SAPFIM

    Joined:
    Dec 29, 2018
    Posts:
    2
    /*I was trying to make a quit feature that would trigger when 'return' was true but discrete it working outside of the if statement when restart was false it seemed to not work in the if statement when return was true. While return is true though and quit was in the if statement pressing 'R' worked just fine despite my attempts to press escape before it to no avail. Does anyone know why? Also feel free to get super into the weeds of it or at least link that sort of material.
    */
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class GameController : MonoBehaviour
    8. {
    9.     public GameObject[] hazards;
    10.     public Vector3 spawnValues;
    11.     public int hazardCount;
    12.     public float spawnWait;
    13.     public float startWait;
    14.     public float waveWait;
    15.  
    16.     public Text scoreText;
    17.     public Text restartText;
    18.     public Text gameOverText;
    19.     public Text escapeText;
    20.     public Text roundText;
    21.  
    22.     float a = 1000.0f;
    23.  
    24.     private bool gameOver;
    25.     private bool restart;
    26.     private int score;
    27.     private int round;
    28.  
    29.     private void Start()
    30.     {
    31.         gameOver = false;
    32.         restart = false;
    33.         restartText.text = "";
    34.         gameOverText.text = "";
    35.         escapeText.text = "";
    36.         score = 0;
    37.         round = 1;
    38.         UpdateRound();
    39.         UpdateScore();
    40.         StartCoroutine (SpawnWaves());
    41.     }
    42.  
    43.     private void Update()
    44.     {
    45.         if (restart)
    46.         {
    47.             if (Input.GetKeyDown(KeyCode.R))
    48.             {
    49.                 SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    50.             }
    51.             if (Input.GetKeyDown(KeyCode.Escape))
    52.             {
    53.                 Application.Quit();
    54.             }
    55.  
    56.         }
    57.        
    58.     }
    59.  
    60.     IEnumerator SpawnWaves()
    61.     {
    62.         while (!gameOver)
    63.         {
    64.             yield return new WaitForSeconds(startWait);
    65.             for (int i = 0; i < hazardCount; i++)
    66.             {
    67.                 GameObject hazard = hazards[Random.Range (0, hazards.Length)];
    68.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    69.                 Quaternion spawnRotation = new Quaternion();
    70.                 Instantiate(hazard, spawnPosition, spawnRotation);
    71.  
    72.                 yield return new WaitForSeconds(spawnWait);
    73.             }
    74.  
    75.             AddRound(1);
    76.             yield return new WaitForSeconds(waveWait);
    77.  
    78.             if (gameOver)
    79.             {
    80.                 restartText.text = "Press 'R' for Restart";
    81.                 escapeText.text = "Escape while you can.";
    82.                 restart = true;
    83.                 break;
    84.             }
    85.         }
    86.     }
    87.  
    88.     public void AddScore(int newScoreValue)
    89.     {
    90.         score += newScoreValue;
    91.         UpdateScore();
    92.     }
    93.  
    94.     void UpdateScore()
    95.     {
    96.         scoreText.text = "Score " + score;
    97.     }
    98.  
    99.     public void AddRound(int newRoundValue)
    100.     {
    101.         round += newRoundValue;
    102.         UpdateRound();
    103.     }
    104.  
    105.     void UpdateRound()
    106.     {
    107.         roundText.text = "Round " + round;
    108.     }
    109.  
    110.     public void GameOver()
    111.     {
    112.         gameOverText.text = "Game Over!";
    113.         gameOver = true;
    114.     }
    115. }
     
  37. BizKwikTwist

    BizKwikTwist

    Joined:
    Jan 27, 2019
    Posts:
    1
    I was wondering if any of the small assets in this package, like the blaster materials and ship thruster particle effects in particular can be used in my own project with ads? Thx in advance for the reply, awesome tutorial btw.
     
  38. notorirandom

    notorirandom

    Joined:
    Jan 20, 2019
    Posts:
    5
    I am learning the chapter Moving the player, i wrote a script as the tutorial says, but I can't make the shooter move. I use VS2017 to write this code. It is worth saying that there is no highlight on the key grammar like "Vector3"...

    Here is the screenshot of the code, thank you for answer my question.
    snipaste20190129_221946.png
     
  39. jeroennees

    jeroennees

    Joined:
    Jul 12, 2018
    Posts:
    5
    The name of the method should be FixedUpdate() (so without the extra 's')
     
  40. gr8crE8r

    gr8crE8r

    Joined:
    Aug 4, 2016
    Posts:
    5
    Hey All! SOMEONE PLEASE HELP!

    I've completed the whole tutorial almost flawlessly, correctly making the changes that were deprecated, and now on the final lesson I'm stumped...

    The 'Evasive Maneuver' script is causing my 'Enemy Ship' to spawn randomly in different places on the screen and not follow the 'Mover' script. The 'Mover' script works when I turn off the 'Evasive Maneuver' script. So there's something going on in 'Evasive Maneuver' that must be causing this.

    **EDIT** Ok... I've gone through the tutorial a second time with scrutiny to make sure I didn't miss something and have made sure I've done everything EXACTLY the way it was done in the tutorial. And the problem persists :(... I have no idea why this is happening and I've tried several different ways of implementing the 'currentSpeed' and various properties to fix the issue...to no avail...

    Any help to troubleshoot this would be super appreciated! I've been at this for over 48 hours now trying to sort it out. I'm begging for help at this point... Anyone???

    Here's my code:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class EvasiveManeuver : MonoBehaviour {
    7.  
    8.     public float tilt;
    9.     public float dodge;
    10.     public float smoothing;
    11.     public Vector2 startWait;
    12.     public Vector2 maneuverTime;
    13.     public Vector2 maneuverWait;
    14.     public Boundary boundary;
    15.  
    16.     private float currentSpeed;
    17.     private float targetManeuver;
    18.     private Rigidbody rb;
    19.  
    20.     void Start () {
    21.         rb = GetComponent<Rigidbody> ();
    22.         currentSpeed = rb.velocity.z;
    23.         StartCoroutine (Evade ());
    24.     }
    25.  
    26.     IEnumerator Evade () {
    27.  
    28.         yield return new WaitForSeconds (Random.Range (startWait.x, startWait.y));
    29.  
    30.         while (true) {
    31.  
    32.             targetManeuver = Random.Range (1, dodge) * -Mathf.Sign (transform.position.x);
    33.             yield return new WaitForSeconds (Random.Range (maneuverTime.x, maneuverTime.y));
    34.             targetManeuver = 0;
    35.             yield return new WaitForSeconds (Random.Range (maneuverWait.x, maneuverWait.y));
    36.         }
    37.     }
    38.  
    39.     void FixedUpdate () {
    40.  
    41.         float newManeuver = Mathf.MoveTowards (rb.velocity.x, targetManeuver, Time.deltaTime * smoothing);
    42.         rb.velocity = new Vector3 (newManeuver, 0.0f, currentSpeed);
    43.  
    44.         rb.position = new Vector3 (
    45.  
    46.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    47.             0.0f,
    48.             Mathf.Clamp (rb.position.x, boundary.zMin, boundary.zMax)
    49.         );
    50.  
    51.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    52.     }
    53. }
    54.  
     
    Last edited: Feb 6, 2019
  41. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    At line 48 you have:
    Mathf.Clamp (rb.position.x, boundary.zMin, boundary.zMax)
    I think you want:
    Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)

    (rb.position.x should be rb.position.z)
     
  42. unity_UJ-vpedmDIQGcQ

    unity_UJ-vpedmDIQGcQ

    Joined:
    Feb 5, 2019
    Posts:
    2
    Yes! Thank you for posting your solution, I was in the same problem. Now it is solved.
     
  43. LJHough

    LJHough

    Joined:
    Feb 13, 2019
    Posts:
    1
    I'm not sure if this is the right area to ask a question. I'm using the space shooter tutorial and I'm on the spawning waves segment. It keeps giving me issues with WaitForSeconds and it doesn't seem to recognize yield at all. Here is my current code.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class GameController : MonoBehaviour
    {
    public GameObject hazard;
    public Vector3 spawnValues;
    public int hazardCount;
    public float spawnWait;
    public float startWait;
    public float waveWait;
    void Start()
    {
    StartCoroutine (SpawnWaves());
    }
    IEnumerator SpawnWaves()
    {
    yeild return new WaitForSeconds (startWait);
    while (true)
    {
    for (int i = 0; i < hazardCount; i++)
    {
    Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    Quaternion spawnRotation = Quaternion.identity;
    Instantiate(hazard, spawnPosition, spawnRotation);
    yeild return new WaitForSeconds(spawnWait);
    }
    yeild return new WaitForSeconds(waveWait);
    }
    }
    }


    This keeps giving me three different errors and I can't fix it. Please tell me what I'm doing wrong!
     
  44. notorirandom

    notorirandom

    Joined:
    Jan 20, 2019
    Posts:
    5
    Thank you very much, i also found that problem before and fix it. Keep learning
     
  45. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144

    You are probably getting errors on the lines where you have the keyword: "yeild"
    You have the error because the correct spelling of the keyword is: "yield"

    Also, when you post your code, please use code tags, it greatly enhances readability

    And, post the actual error messages as well
     
  46. Admiral-Jason

    Admiral-Jason

    Joined:
    Oct 14, 2018
    Posts:
    28
    Hello,
    I've worked through the tutorial and even made some modifications (top ten scores). Everything was working the way it was suppose to then it started to have an issue. When the player crashes into an asteroid, the asteroid is destroyed, the explosion is played, but the player's ship is not destroyed! Here is the code for DestroyByContact.cs:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class DestroyByContact : MonoBehaviour
    7. {
    8.     public GameObject explosion;
    9.     public GameObject playerExplosion;
    10.     public int scoreValue;
    11.     private GameController gameController;
    12.  
    13.     private void Start()
    14.     {
    15.         GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");
    16.         if(gameControllerObject != null)
    17.         {
    18.             gameController = gameControllerObject.GetComponent<GameController>();
    19.         }
    20.         if(gameController == null)
    21.         {
    22.             Debug.Log("Cannot find 'GameController' Script");
    23.         }
    24.     }
    25.  
    26.     private void OnTriggerEnter(Collider other)
    27.     {
    28.         if (other.tag == "Boundary")
    29.         {
    30.             return;
    31.         }
    32.         Instantiate(explosion, transform.position, transform.rotation);
    33.         if (other.tag == "Player")
    34.         {
    35.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    36.             gameController.GameOver();
    37.         }
    38.         gameController.AddScore(scoreValue);
    39.         Destroy(other.gameObject);
    40.         Destroy(gameObject);
    41.     }
    42.  
    43. }
    44.  
    Ironically, I haven't changed anything in this script. Any Ideas?

    **UPDATE**
    I fixed it! I had the section of code pressing 'R' to restart still in the Update() method. As a result, it would reload the main scene instantly instead of the splash screen I made. So it always seemed like it wasn't destroying the player ship. Lesson Learned: it's always important to clean up your code when changing something.
     
    Last edited: Feb 24, 2019
  47. KrySoar

    KrySoar

    Joined:
    Feb 28, 2019
    Posts:
    2
    MsHammie likes this.
  48. quinzel12

    quinzel12

    Joined:
    Feb 27, 2019
    Posts:
    2
    Currently cannot access the Upgrade Guide for Unity 5, when will it be available again?
     
    MsHammie likes this.
  49. KrySoar

    KrySoar

    Joined:
    Feb 28, 2019
    Posts:
    2
    It is now available for me !
     
  50. Twisted_Code

    Twisted_Code

    Joined:
    Mar 6, 2019
    Posts:
    3
    I'm having a bit of trouble finding/accessing the tutorial videos, and was only able to find this thread from the tutorial section of the website, because the links in the tutorial (such as the ones in the Inspector when the project is initialized) aren't working for me. I'm not sure if it's something with this tutorial, with my unity installation itself, or otherwise, but when I click them, all that happens is the Title Bar briefly flashes, and then... nothing. It's like it's trying to open the link in my system, but the system doesn't understand the link, or something? does anyone know why I might be having trouble opening links? Because I'm pretty much clueless here.
     
    Last edited: Mar 6, 2019