Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. We're running great holiday deals on subscriptions, swag and Asset Store packages! Take a peek at this blog for more information!
    Dismiss Notice
  3. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  4. Unity 2017.2 is now released.
    Dismiss Notice
  5. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  6. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  8. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Space Shooter Tutorial Q&A

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

  1. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    This is the official thread for discussion, issues and Q&A for the Space Shooter tutorial.

    Please use this thread if you have any questions, issues or feedback on this project.

    Space Shooter is a learning project on our Learn Site:
    http://unity3d.com/learn/tutorials/projects/space-shooter-tutorial

    Expand your knowledge and experience of working with Unity by creating a simple top down arcade style shooter. Using basic assets provided by Unity Technologies, built-in components and writing simple custom code, understand how to work with imported Mesh Models, Audio, Textures and Materials while practicing more complicated Scripting principles.

    -

    Upgrade Guide:


    Common Upgrade Issues (please see the upgrade guide for details):

    • Unity 5: When using the mesh collider and adding the simplified mesh, the mesh collider must be "convex" when using Unity 5. Please check "convex" on the mesh collider component.
    • Unity 5: Ambient light is now set differently. Please delete the default skybox from the Lighting panel and make sure it is set to "None".
    • Unity 5: Common components are no longer cached and there are no "helper references" access them.
    Common Misunderstandings:
    • My GUIText is not visible on the screen
      • Check to make sure that the Transform Position x and y values are between 0 and 1.
      • In the Transform Position x value is either of the extremes of 0 or 1, make sure that the alignment is not pushing the text off of the screen.
      • Check that any "Parent" GameObject (like a holder game object) is set to "origin", or (0,0,0) in its Transform Position.
    • My Bolt Object is laggy when fired
      • Make sure you have the Rigidbody component set according to the steps in the video and that you only have one Rigidbody in the GameObject family (eg: You don't have one Rigidbody on the root and one on the VFX Quad).

    For the archived thread please use this link:
    http://forum.unity3d.com/threads/space-shooter-tutorial-q-a-archived.222119
     
  2. cantRecall

    cantRecall

    Joined:
    Mar 26, 2015
    Posts:
    2
    I am having a problem were a little speaker and a line are being shown on the game screen underneath the player ship. I got the text to work by importing UnityEngine.UI then changing scoreText variable from GUIText to Text. And using the canvas text object.
     
  3. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    If you have gizmos visible in the Game View, you probably have "Gizmo's" turned on:
    Screenshot 2015-03-27 10.49.19.png

    You should try making sure it's turned off:
    Screenshot 2015-03-27 10.49.29.png
     
  4. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    Using the UI Text elements is a good idea. Glad you figured it out.

    The solution to using GUIText is annotated in the video and is listed in the OP.
     
  5. cantRecall

    cantRecall

    Joined:
    Mar 26, 2015
    Posts:
    2
    I did have the sound gizmo and the canvas gizmo turned on though I don't remember turning them on. Is this the default action when you add a canvas or sound object? Thanks for your reply.

    I'm sorry but after testing I found the sound gizmo was still there. The line disappeared when I turned the canvas gizmo off. I went to the scene view and highlighted it and it was the player controller script that placed the sound gizmo in the game when played as there was a audio source component attached to it. I set the player controller script to 17 on the zed axis to move it out of the scene and that worked. This happened when I created the canvas text object and dragged the Text object onto the player controller script.
     
    Last edited: Mar 27, 2015
  6. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    stuck again, I am working on the part to add a score to the game. After following the instructions I am getting 19 errors. I went through and found a few typo's on my end, but that seem to make it worse. I even copy pasted from website over. Not sure what I am doing wrong now.
     
  7. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Game_Controller : MonoBehaviour
    5.  
    6. {
    7.     public GameObject hazard;
    8.     public Vector3 spawnValues;
    9.     public int hazardCount;
    10.     public float spawnWait;
    11.     public float startWait;
    12.     public float waveWait;
    13.     public GUIText scoreText;
    14.  
    15.     private int score;
    16.  
    17.     void Start ()
    18.  
    19.     {
    20.         score = 0;
    21.         UpdateScore ();
    22.         StartCoroutine (Spawnwaves ());
    23.  
    24.     }
    25.  
    26.    
    27.     IEnumerator Spawnwaves ()
    28.  
    29.     {
    30.         yield return new WaitForSeconds (startWait);
    31.         while (true)
    32.      
    33.         {
    34.  
    35.             for (int i = 0; i < hazardCount; i++)
    36.          
    37.             {
    38.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    39.                 Quaternion spawnRotation = Quaternion.identity;
    40.                 Instantiate (hazard, spawnPosition, spawnRotation);
    41.                 yield return new WaitForSeconds (spawnWait);
    42.             }
    43.  
    44.             yield return new WaitForSeconds (waveWait);
    45.  
    46.         }
    47.  
    48.           public void AddScore (int newScoreValue)
    49.  
    50.         {
    51.  
    52.             score += newScoreValue;
    53.             UpdateScore ();
    54.  
    55.         }
    56.  
    57.         void UpdateScore ()
    58.  
    59.         {
    60.  
    61.             scoreText.text = "Score: " + score;  
    62.  
    63.         }
    64.     }
    65.  
    66. }
     
  8. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Destroy_by_Contact : MonoBehaviour
    5.  
    6. {
    7.     public GameObject explosion;
    8.     public GameObject playerexplosion;
    9.     public int scoreValue;
    10.     private GameController gameController;
    11.  
    12.  
    13.     void Start ()
    14.     {
    15.         GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    16.  
    17.         if (gameControllerObject != null)
    18.  
    19.         {
    20.  
    21.             gameController = gameControllerObject.GetComponent <GameController>();
    22.        
    23.         }
    24.  
    25.         if (gameController == null)
    26.        
    27.         {
    28.        
    29.             Debug.Log ("Cannot find 'GameController' script");
    30.        
    31.         }
    32.  
    33.  
    34.     void OnTriggerEnter(Collider other)
    35.  
    36.     {
    37.         // as long as boundary is tagged it will not destroy new objects in area until reaches proper code
    38.         // remember to create a tag in Unity called Boundary set it and save scene before testing.
    39.         if (other.tag == "Boundary")
    40.        
    41.         {
    42.             return;
    43.  
    44.         }
    45.  
    46.         Instantiate (explosion, transform.position, transform.rotation);
    47.         if (other.tag == "Player")
    48.        
    49.         {
    50.             Instantiate (playerexplosion, other.transform.position, other.transform.rotation);
    51.  
    52.         }
    53.  
    54.             gameController.AddScore (scoreValue);
    55.         Destroy (other.gameObject);
    56.         Destroy (gameObject);
    57.  
    58.     }
    59.  
    60. }
     
  9. bmwall

    bmwall

    Joined:
    Mar 28, 2015
    Posts:
    2
    I am having a problem with creating the bolts. My code for the Mover script is a mirror image of the script in the done folder. I follow everything in the tutorial but when I remove the bolt from the hierarchy and instantiate it while running the game like in the tutorial, it doesn't move but just sits static on the view. Any idea what it could be?
     
  10. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    Double check that all the settings in the GameObject have been applied to the prefab before deleting.

    You can also simply inspect the prefab and look at the values and components there and make adjustments directly to the prefab asset.
     
  11. bmwall

    bmwall

    Joined:
    Mar 28, 2015
    Posts:
    2
    I will do that now. Also, if it helps, I am receiving the error message ''Non-convex MeshColliders with non-Kinematic rigidbodies are no longer supported in Unity 5''.
     
  12. jordyvandertang

    jordyvandertang

    Joined:
    Mar 26, 2015
    Posts:
    2
    Edit: Of Course writing Start() with a capital S would help referencing the rigidbody -.- . I'll leave this post here for now.. but the problem should be solved.

    Hello Adam,

    I took my first steps into unity by following your roll a ball tutorial. I was very happy to find that I did not run into any errors I could not solve myself.

    Unfortunately I've not been so lucky with the Space Shooter tutorial.. I got stuck on the basic movement script.

    I referenced the rigidbody in the start() after creating a private variable for it. However, my ship is unable to move, and the console is telling me:
    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:20)
    4.  
    my code is below, I checked it with the basic movement script used for the roll a ball tutorial, which worked fine, but could not find any differences.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     private Rigidbody rig;
    7.  
    8.     void start()
    9.     {
    10.         rig = GetComponent<Rigidbody> ();
    11.     }
    12.     void FixedUpdate()
    13.     {
    14.  
    15.         float moveHorizontal = Input.GetAxis ("Horizontal");
    16.         float moveVertical = Input.GetAxis ("Vertical");
    17.  
    18.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    19.  
    20.         rig.velocity = movement;
    21.     }
    22.  
    23. }
    24.  
    The console tells me to look at line 20, however I can not comprehend what is wrong with this line, or earlier declarations of the rigidbody in the code.

    Thank you for your help in advance.
     
    Last edited: Mar 28, 2015
  13. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    This is covered in the original post as a known issue. It's a change with the way the physics system works in Unity 5. You need to make sure the mesh collider is convex. See the original post for more detail.
     
  14. paul81

    paul81

    Joined:
    Feb 11, 2015
    Posts:
    10
    Evening all

    currently going through the space shooter tutorial, and everything has gone okay, until actually firing the bloody shots! lol

    they fire fine when actually dragging the bolt icon onto the shot spawn bit, but when actually controlling and using left ctrl to fire (as instructed in the input manager) the ship flies fine, but nothing shoots out?

    code seems fine, but my ships lacking umph!

    cheers in advance!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class  Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9. public class PlayerController : MonoBehaviour
    10. {
    11.     private Rigidbody Rigidbody;
    12.  
    13.     public float speed;
    14.     public float tilt;
    15.     public Boundary boundary;
    16.  
    17.     public GameObject shot;
    18.     public Transform shotSpawn;
    19.     public float fireRate;
    20.  
    21.     private float nextFire;
    22.  
    23.  
    24.     void update ()
    25.     {
    26.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    27.         {  
    28.             nextFire = Time.time + fireRate;
    29.         //    GameObject clone =
    30.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    31.         }
    32.     }
    33.     void Start (){
    34.     Rigidbody = GetComponent<Rigidbody> ();
    35.     }
    36.     void FixedUpdate ()
    37.     {
    38.         float moveHorizontal = Input.GetAxis ("Horizontal");
    39.         float moveVertical = Input.GetAxis ("Vertical");
    40.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    41.         Rigidbody.velocity = movement * speed;
    42.  
    43.         Rigidbody.position = new Vector3
    44.         (
    45.                 Mathf.Clamp (Rigidbody.position.x, boundary.xMin, boundary.xMax),
    46.                 0.0f,
    47.                 Mathf.Clamp (Rigidbody.position.z, boundary.zMin, boundary.zMax)
    48.         );
    49.         Rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, Rigidbody.velocity.x * -tilt);
    50.     }
    51. }
    52.  
     
  15. MORVOC

    MORVOC

    Joined:
    Mar 31, 2015
    Posts:
    4
    I'm not sure if this is the right place to be asking this... but... I was doing a similar space shooter project and managed to add player controls for the keyboard. I wanted to see if there was a way to convert the controls so it would be able to be played across ios devices through some sort of a joystick and shoot button instead of W, A, S, D and space to shoot. I really wanted to finish this project, and so far it's the last thing I have to complete it. I'm pretty new to this and have been looking all over the forums for a good explanation for months now... most of them I was able to try... with no luck though... this was my last hope. :(
     
  16. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
  17. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    A few things I've noticed:

    Line 11: you have "private Rigidbody Rigidbody;" because of the capitalisation, you don't have "an access modifier, a type and a name" you have "an access modifier, a type and a type". You need to use another name other than the name of the type as Rigidbody. A common convention is to use rb.

    This is true of line 34 as well. And 40, 42, 44 etc.

    Are you getting any errors?

    And...

    What's line 40 doing in there? That's a redundant line that seems related yo the hazards!
     
    paul81 likes this.
  18. paul81

    paul81

    Joined:
    Feb 11, 2015
    Posts:
    10
    Hi Adam

    many thanks for getting back to me!

    as you probably gathered, unity is my first jump into coding, so it might look a bit of a bodge job at the moment, but hopefully i'll get there!! :D

    tidied up the code a bit, made the changes you suggested, but still no firing. no errors coming up either

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5.     public class  Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9. public class PlayerController : MonoBehaviour
    10. {
    11.     private Rigidbody rb;
    12.  
    13.     public float speed;
    14.     public float tilt;
    15.     public Boundary boundary;
    16.  
    17.     public GameObject shot;
    18.     public Transform shotSpawn;
    19.     public float fireRate;
    20.  
    21.     private float nextFire;
    22.  
    23.  
    24.     void update ()
    25.     {
    26.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    27.         {  
    28.             nextFire = Time.time + fireRate;
    29.         //    GameObject clone =
    30.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    31.         }
    32.     }
    33.     void Start (){
    34.     rb = GetComponent<Rigidbody> ();
    35.     }
    36.     void FixedUpdate ()
    37.     {
    38.         float moveHorizontal = Input.GetAxis ("Horizontal");
    39.         float moveVertical = Input.GetAxis ("Vertical");
    40.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    41.         rb.velocity = movement * speed;
    42.  
    43.         rb.position = new Vector3
    44.         (
    45.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    46.                 0.0f,
    47.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    48.         );
    49.         rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    50.     }
    51. }
    52.  
     
  19. MORVOC

    MORVOC

    Joined:
    Mar 31, 2015
    Posts:
    4
    Thank you so much for referring me to this tutorial OboShape, I'll try and check it out as soon as I can and hopefully I'll be able to get my game working...
     
  20. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
    Evening @paul81 Where you have the update function above. this should be changed to a capital U in Update.

    Code (CSharp):
    1. void Update ()
    this is case sensitive, as 'update()' and 'Update()' are treated as two distinctively different function names.
     
    paul81 likes this.
  21. farber

    farber

    Joined:
    Mar 31, 2015
    Posts:
    2
    Anyone else unable to see the mesh collider in Unity 5 once you turn off the mesh render? At about 6:35 in the 3rd video he says to turn off the mesh render to get a better look at the mesh collider. When I do that all that's left is a gizmo and I don't see any green lines of the mesh ?
     
  22. paul81

    paul81

    Joined:
    Feb 11, 2015
    Posts:
    10
    Honestly cant believe i missed that one! I know im new to coding, but its a school boy error! Lol!
    Shall sort that when i get back in, hopefully it'll fix it!

    Many thanks!
     
  23. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    Make sure the mesh component is open. If the turn down is closed on a component it will hide the gizmos in the scene.
     
  24. paul81

    paul81

    Joined:
    Feb 11, 2015
    Posts:
    10
    @OboShape just so you know, the slight change for the Update worked like a charm, my ship is no longer firing blanks!

    i owe you a beer!! Many thanks!
     
    OboShape and Jeriko2k3 like this.
  25. farber

    farber

    Joined:
    Mar 31, 2015
    Posts:
    2
    I really was looking for a yes or no here - Anyone else able to see the mesh collider once the mesh render is turned off in Unity 5. Adam your response didn't make any sense to me - I am doing the exact steps you did. Have you tried doing this project in Unity 5 yet ?
     
  26. Iommi

    Iommi

    Joined:
    Apr 3, 2015
    Posts:
    1
    Hi all,

    im currently working on this tutorial and have some issues moving the laser-shots ...

    if im using
    Code (CSharp):
    1. rigidbody.velocity = transform.forward * speed;
    not only the z-value is manipulated, but also the y value ...

    i currently solve this issue by resetting the y value to zero every FixedUpdate();

    Code (CSharp):
    1.     void FixedUpdate(){
    2.         Vector3 accord = new Vector3 (GetComponent<Rigidbody> ().position.x, 0, GetComponent<Rigidbody> ().position.z);
    3.         GetComponent<Rigidbody> ().position = accord;
    4.     }
    but thats just a dirty walkaround ...

    does anyone have the same issue or can explain why "transform.forward" also effects the y-value?
    Both, the Shot prefab and the VFX, are at origin (0,0,0) ...

    Thanks, and happy Easter =)
    Iommi

    €: @ farber: yeah i had the same issue, mark the convex checkbox, and it will become visible
     

    Attached Files:

  27. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
    hi @farber
    here is an image to show you what Adam was mentioning about not being open (as in not seeing the contents of the component)
    [​IMG]
    this bit in the inspector, ensure that this 'Mesh Collider' part of the inspector is visible. so you can see convex, and is trigger.
    and that theres a tick next to Convex.

    as if you aren't showing the contents (collapsed) the collider will not show in editor window.
     
    SilvercordBand likes this.
  28. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
    @lommi you could turn look in the Contraints in the rigidbody, and limit the movement on the Y plane.

    as to the why, im unsure im afraid, unless theres a slight rotation.
     
  29. ssnowmann11

    ssnowmann11

    Joined:
    Apr 3, 2015
    Posts:
    2
    @lommi your issue is simply that you still have the rigidbody as being under the influence of gravity. Uncheck that box and you should be good to go!
     
  30. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    Well. You shouldn't get any y value change. Are you using gravity by accident? Either that, or the collider is not a trigger, and it's bumping into something? The ship? And getting thrown off trajectory, but that should be corrected after the first reset of the y... I'd suggest gravity is the culprit.
     
  31. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    Heya,

    First off, Thank you, All of you... I can not stress enough how having a resource like this is appreciated!

    I'm normally more of an Asset creator, yet I've just got through the tutorial in the newest build, only real problem was the Collider (Convex) issue and a few updates to the API (GetComponent<Rigidbody>().velocity now, instead of rigidbody.velocity... but the Unity catches and fixes that and the tip in the first post clears it up!),

    I've hobbled together a Health system for it, and a Kill counter, used the Offset/Parallax background method from it's own tutorial , added in my own Models and Audio and have had a blast so far! (haven't figured out the enemy stuff yet).

    Not having read through the entire thread (and it's archived sister heh!) I was wondering if any of you guys know of Guides/Info towards some sort of level/scene loading system that would work well for these kind of entry level projects, So one could clone, tweak, rearrange the scene, and call it as a second level after x points/kills with out too much hassle?


    Mostly though... Thanks!
     
  32. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    Lay out your tweaked scene in a new scene file. You can duplicate the scene file in the project view if you want to. Tweak as necessary. Make sure all wanted scenes are loaded into the build window. Instead of loading the loaded level, load the new one by name or index number.
     
  33. Patrel

    Patrel

    Joined:
    Mar 24, 2015
    Posts:
    6
    I am only stuck on the Ending a Game chapter. The R button on my keyboard doesn't work to restart the game. Anyone able to help point me to the incorrect code?


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class GameController : MonoBehaviour
    6. {
    7.     public GameObject hazard;
    8.     public Vector3 spawnValues;
    9.     public int hazardCount;
    10.     public float spawnWait;
    11.     public float startWait;
    12.     public float waveWait;
    13.  
    14.     public GUIText scoreText;
    15.     public GUIText restartText;
    16.     public GUIText gameOverText;
    17.  
    18.     private bool gameOver;
    19.     private bool restart;
    20.     private int score;
    21.  
    22.     void Start ()
    23.     {
    24.         gameOver = false;
    25.         restart = false;
    26.         restartText.text = "";
    27.         gameOverText.text = "";
    28.         score = 0;
    29.         UpdateScore ();
    30.         StartCoroutine (SpawnWaves ());
    31.     }
    32.  
    33.     void update ()
    34.     {
    35.         if (restart)
    36.         {
    37.             if (Input.GetKeyDown (KeyCode.R))
    38.             {
    39.                 Application.LoadLevel (Application.loadedLevel);
    40.             }
    41.         }
    42.     }
    43.     IEnumerator SpawnWaves ()
    44.     {
    45.         yield return new WaitForSeconds (startWait);
    46.         while (true)
    47.         {
    48.             for (int i = 0; i < hazardCount; i++)
    49.             {
    50.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    51.                 Quaternion spawnRotation = Quaternion.identity;
    52.                 Instantiate (hazard, spawnPosition, spawnRotation);
    53.                 yield return new WaitForSeconds (spawnWait);
    54.             }
    55.             yield return new WaitForSeconds (waveWait);
    56.  
    57.             if (gameOver)
    58.             {
    59.                 restartText.text = "Press 'R' for Restart";
    60.                 restart = true;
    61.                 break;
    62.             }
    63.  
    64.         }
    65.     }
    66.  
    67.     public void AddScore (int newScoreValue)
    68.     {
    69.         score += newScoreValue;
    70.         UpdateScore ();
    71.     }
    72.  
    73.     void UpdateScore()
    74.     {
    75.         scoreText.text = "Score: " + score;
    76.     }
    77.  
    78.     public void GameOver ()
    79.     {
    80.         gameOverText.text = "Game Over!";
    81.         gameOver = true;
    82.     }
    83. }
    84. [CODE]
     
    technano likes this.
  34. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    Line 33: update needs to be Update with a capital "U"! (Don't forget the scripting languages for Unity are CaSeSensitivE!)
     
    reyloko55 and technano like this.
  35. n0vice

    n0vice

    Joined:
    Apr 8, 2015
    Posts:
    4
    Hi Adam,

    I'm following up from this thread - http://forum.unity3d.com/threads/qu...m-space-shooter-tutorial.312692/#post-2058651

    Thanks very much for your reply. I really appreciate your help. I do understand that the error means I'm trying to access a Rigidbody on the camera component, but as I said, I have only one Rigidbody component, and it is attached to the "Player" game object.
    Secondly, I'm sorry but I do not understand what you mean by "Is the script on the wrong GameObject? Shouldn't this be on the player GameObject?"

    What do you mean by a script being "on a game object"? I followed the steps from the tutorial and created the script called PlayerController in a folder named Scripts in Assets.

    What am I doing wrong?
     
  36. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    What is that script attached to? A script needs to be attached to a GameObject at is instantiated in an active scene to work.

    There are several ways you can create a new script: the assets/create in the main menu, the project view's create menu, a right- (or context-) click the project view and the "Add Component" button on a GameObject. If you use the add component button, this will create and add the script to the GameObject that was being inspected.

    You probably had the Camera selected, not the Player GameObject, when you used the Add Component" button, which then attached it to the Camera, not the Player.

    Use the context sensitive gear menu on the script component on the Camera GameObject and remove the script from the Camera. Then, select the Player GameObject and drag the script from the project view onto the inspector while the Player is selected to attach the script to Player GameObject.
     
  37. n0vice

    n0vice

    Joined:
    Apr 8, 2015
    Posts:
    4
    Thanks a ton Adam, it worked! :)
     
  38. n0vice

    n0vice

    Joined:
    Apr 8, 2015
    Posts:
    4
    I'm on the shooting shots tutorial. Everything works fine but my shots work with the control key on my mac instead of the space bar. How can I change it?
     
  39. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    NobleRogue likes this.
  40. RaptorSap

    RaptorSap

    Joined:
    Apr 11, 2015
    Posts:
    1
    Hello, in the "Creating Hazards" lesson there is a line of debugging code that is supposed to return the name of the gameObject that is triggering the collider and causing the asteroid to despawn. My asteroid despawns just like in the video, so the rest of the code seems to be functional, but I can't get Unity to return any debugging information. My code is below:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByContact : MonoBehaviour {
    5.     void OnTriggerEnter(Collider other) {
    6.         Debug.Log (other.name);
    7.         Destroy(other.gameObject);
    8.         Destroy(gameObject);
    9.     }
    10. }
     
  41. Pando

    Pando

    Joined:
    May 26, 2014
    Posts:
    2
    Hi,

    I would like to point to another problem I'm facing in the Creating Hazards part of the tutorial too.

    It has already been reported by the comment that should be associated to this link to the youtube video.

    I have the exact same problem using Unity 5: a bolt is getting fired at the game start when entering play mode, immediately destroying the asteroid, both when clicking the Play button or hitting Ctrl-P (on Windows).
    I have checked everything from scripts to objects transforms, I watched the video several times and I can't seem to understand why !

    The answer to this comment, i.e. disabling the Shot Spawn object in the Player object, actually works for me. But it seems hacky, and I'm curious about what's really wrong.

    Please forgive me if the answer already lies in here somewhere. I haven't been able to find it. :(
     
  42. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    If you have a bolt firing instantly on hitting Play, check to see if you have left an instance of Bolt in the scene hierarchy.

    Once you set it as a prefab, and add it to the public variable on your PlayerController script, it should be removed from the scene and will be instantiated when you hit "Fire 1" if you have kept the default keys.

    Any bolts left in the scene will trigger their Mover script on play.
     
  43. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    You get no note in the console and no note in the footer of the editor? Are you seeing the GameObject being removed from the hierarchy as it's being destroyed?

    Can you just add another debug line:
    Code (csharp):
    1. Debug.Log("DestroyByContact/OnTriggerEnter called!");
    after the line:
    Code (csharp):
    1. void OnTriggerEnter(Collider other) {
    ... just to check that the function is being called correctly?
     
  44. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,669
    @Westyfu has the best suggestion, yes. We will need to create our GameObject in the scene, and then we drag is into our project view to create it as a prefab asset. If we forget to remove the instance that we created in the scene, it's all primed and ready to go when the scene starts, so - it will "fire" as soon as you enter play-mode.

    It's an easy (and common) mistake to make. Simply delete the instance and you'll be fine.

    The reason why deactivating the spawn point works is that the instance is often created as a child of the spawn point, and when you deactivate a parent, it will deactivate the children of that parent, so the bolt - as a child of the spawn point - is now deactivated as well.

    As an aside - it will make no difference what-so-ever in how you enter play-mode. Using either the Play button or hitting Ctrl-P (on Windows) will put the editor into play-mode. There is no functional difference to the way the editor behaves. If you use the "hot key", you will notice that the "button" is depressed as well, and the play-mode tint shows on the button graphics.
     
  45. Pando

    Pando

    Joined:
    May 26, 2014
    Posts:
    2
    Thank both of you, actually I found the right answer in the archived Q&A topic after a few pages, I overlooked it. But that was it ! :)

    For some reason, my ShotSpawn object in the Player still had a child Bolt attached, and I didn't make the connection in my mind between this Bolt and the problem. Deleting it immediately fixed it.

    Anyway, the tutorial is great.Thanks !
     
  46. x_

    x_

    Joined:
    Apr 7, 2015
    Posts:
    2
    I finished the tutorial spaceshooter will change the asteroids by other spaceship and I wonder how I can make spaceships shoot the player ?
    thanks in advance...
     
  47. AlbertoNieto

    AlbertoNieto

    Joined:
    Apr 14, 2015
    Posts:
    4
    I am having problems with the background. I must be doing something wrong but I can't find what it is.

    Here is a screenshot of my background settings:

    [​IMG]
     
  48. christinanorwood

    christinanorwood

    Joined:
    Aug 9, 2013
    Posts:
    402
    Your Y Tiling value is 0, perhaps set it to 1 like the X value?
     
  49. Westyfu

    Westyfu

    Joined:
    Mar 30, 2015
    Posts:
    16
    Don't forget once finished to check out the Completed (Done_) project.

    Within it are Scripts that can help with Enemy shooting (Namely Done_WeaponController.cs) to get you on your way.

    @AlbertoNieto,

    Your tiling options on the material are X.1, Y.0, so the material is not being stretched across the Y axis at all, and being fully stretched across the X axis. Setting both to 1 will stretch it out properly, then setting your offset values to 0 will center it.
     
  50. Wellfooled

    Wellfooled

    Joined:
    Feb 23, 2015
    Posts:
    6
    Hello!

    I've just this morning completed the Counting Points session of the Space Shooter tutorial and its mostly working well, but I'm having an odd problem. When I destroy an asteroid my points rewarded are often times double what they should be, but this isn't consistent. Sometimes it rewards the correct ten points.

    Here are the codes I'm using for my GameController and DestroyByContact (I assume the problem has to be in those somewhere since I think those are the only two that effect the score).

    GameController Code:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine.UI;
    3.  
    4. public class GameController : MonoBehaviour
    5. {
    6.     public GameObject hazard;
    7.     public Vector3 spawnValues;
    8.     public int hazardCount;
    9.     public float spawnWait;
    10.     public float startWait;
    11.     public float waveWait;
    12.  
    13.     public Text scoreText;
    14.     private int score;
    15.  
    16.     void Start ()
    17.     {
    18.         score = 0;
    19.         UpdateScore ();
    20.         StartCoroutine (SpawnWaves ());
    21.     }
    22.  
    23.     IEnumerator SpawnWaves ()
    24.     {
    25.         yield return new WaitForSeconds (startWait);
    26.         while (true)
    27.         {
    28.             for (int i = 0;i < hazardCount;i++)
    29.             {
    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.  
    39.     public void AddScore (int newScoreValue)
    40.     {
    41.         score += newScoreValue;
    42.         UpdateScore ();
    43.     }
    44.  
    45.     void UpdateScore ()
    46.     {
    47.         scoreText.text = "Score: " + score;
    48.     }
    49. }
    DestroyByContact Code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByContact : MonoBehaviour
    5. {
    6.     public GameObject explosion;  
    7.     public GameObject playerExplosion;
    8.     public int scoreValue;
    9.     private GameController gameController;
    10.  
    11.     void Start ()
    12.     {
    13.         GameObject gameControllerObject = GameObject.FindWithTag ("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.  
    24.     void OnTriggerEnter(Collider other)
    25.     {
    26.         if (other.tag == "Boundary")
    27.             {
    28.                 return;
    29.             }
    30.         Instantiate(explosion, transform.position, transform.rotation);
    31.         if (other.tag == "Player")
    32.             {
    33.             Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
    34.             }
    35.         gameController.AddScore (scoreValue);
    36.         Destroy(other.gameObject);
    37.         Destroy(gameObject);
    38.     }
    39. }
    40.    
    Thanks in advance for any help you can give me in figuring this out!

    And on a slightly different topic, I'm having trouble understanding this line of code from the tutorial.

    Code (CSharp):
    1. public void AddScore (int newScoreValue)
    2.     {
    3.         score += newScoreValue;
    4.         UpdateScore ();
    5.     }
    Can anyone please explain this to me in detail? I understand that its changing the value of score and that its then updating the displayed number for score in the game, but I don't think I'm grasping how its going about that. Thank you!
     
    schwab likes this.