Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Space Shooter Tutorial Q&A

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

  1. jigsy1

    jigsy1

    Joined:
    Nov 21, 2015
    Posts:
    7
    Fear not everyone, it was a simple case of changing the 'start' to 'Start.' this might be helpful for anyone receiving the same error message.
     
  2. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Paying attention would also be helpful.

    Read, again and again, your scripts before asking questions. Most of the time you'll find answers by yourself.

    Also, when you post a script here, use the proper tags:

    Sans titre-1.jpg
     
  3. xuanquang1999

    xuanquang1999

    Joined:
    Jul 12, 2016
    Posts:
    4
    upload_2016-7-15_14-16-50.png

    I'm having a weird problem. In Unity, everything works fine. But when I build the project to the web, the player ship, the asteroid become invisible. I don't know why.
     
  4. ToxicGinger

    ToxicGinger

    Joined:
    Jul 15, 2016
    Posts:
    1
    Hi,
    I'm following the tutorial but I'm using my own asset for the player ship. Due to this, my asset needs a default rotation of 270 on the x axis. This appears to be causing a problem when using Quaternion.Euler to rotate the ship as it moves. Rather than rotating on the z axis, the ship appears to rotate on the y axis. Could someone please help me work out what I am doing wrong. Thank You.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary{
    6.     public float xMin, xMax,zMin, zMax;
    7.  
    8. }
    9.  
    10. public class PlayerController : MonoBehaviour {
    11.  
    12.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.     private Rigidbody rb;
    16.  
    17.     void Start ()
    18.     {
    19.         rb = GetComponent<Rigidbody>();
    20.     }
    21.  
    22.     void FixedUpdate () {
    23.         float moveHorizontal = Input.GetAxis ("Horizontal");
    24.         float moveVertical = Input.GetAxis ("Vertical");
    25.  
    26.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    27.         rb.velocity = movement * speed;
    28.  
    29.         rb.position = new Vector3 (Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax), 0, Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax));
    30.         rb.rotation = Quaternion.Euler (270.0f, 0.0f, rb.velocity.x * -tilt );
    31.     }
    32. }
    33.  
     
  5. lreyes527

    lreyes527

    Joined:
    Jul 17, 2016
    Posts:
    2
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    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 GUIText 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. }
    50.  
    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 (gameController != 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.             Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
    33.         }
    34.         gameController.AddScore (scoreValue);
    35.         Destroy (other.gameObject);
    36.         Destroy (gameObject);
    37.     }
    38.  
    39. }
    40.  
    I am at the counting points part of tutorial. I receive this error
    NullReferenceException: Object reference not set to an instance of an object
    DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/DestroyByContact.cs:34
     
  6. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    on your line 14 in your DestroyByContact script, this will always be Null and it will never try to find and assign the gameController component.

    So in your Start method, you currently have

    Code (CSharp):
    1. GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    2.         if (gameController != null)
    but, you are finding the gameobject and assigning it, but, you then have to check that the gameControllerObject is not NULL.
    so this should read.

    Code (CSharp):
    1. GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    2.         if (gameControllerObject != null)
    see how you get on with that.
     
  7. lreyes527

    lreyes527

    Joined:
    Jul 17, 2016
    Posts:
    2
    Works perfect now thanks. I tried checking my script over and over again and couldn't find the error. Needed another pair of eyes to help me out.
     
  8. EdGann

    EdGann

    Joined:
    Jul 17, 2016
    Posts:
    8
    So I have been working through this tutorial and I find that the Application.Loadlevel is no longer used. I created a reference to scenemanagment and used scenemanager to restart the game, and works fine, but I am wondering if this is the best way?

    void Update ()
    {
    if (restart)
    {
    if (Input.GetKeyDown (KeyCode.R))
    {
    curScene=SceneManager.GetActiveScene();
    SceneManager.LoadScene(curScene.buildIndex);
    }
    }
    }

    Thanks
     
  9. mannyhams

    mannyhams

    Joined:
    Feb 6, 2015
    Posts:
    34
    Hey all :)
    Was hoping to be able to set default values for the public members of `Boundary` so Unity would reset to them on each compile, even if I had changed those values previously through the gui:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [System.Serializable]
    6. public class Boundary {
    7.     public float xMin = -6.0f,
    8.     xMax = 6.0f,
    9.     zMin = -4.0f,
    10.     zMax = 8.0f;
    11. }
    12.  
    13. public class PlayerController : MonoBehaviour {
    14.  
    15.     private Rigidbody rb;
    16.     public float speed ;
    17.     public Boundary boundary;
    18.  
    19.     void Start () {
    20.         rb = GetComponent<Rigidbody> ();
    21.     }
    22.  
    23.     void FixedUpdate () {
    24.         float moveHorizontal = Input.GetAxis ("Horizontal");
    25.         float moveVertical = Input.GetAxis ("Vertical");
    26.  
    27.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    28.         rb.velocity = movement * speed;
    29.  
    30.         rb.position = new Vector3 (
    31.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    32.             0.0f,
    33.             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    34.         );
    35.     }
    36.  
    37. }
    38.  
    Doesn't work. Is there another way to set default values for public members? I am assuming I can't set them through a `start` method on `Boundary` since that is probably being inherited from MonoBehavior... what would happen if I have both these classes inherit from MonoBehavior in the same file?

    Thanks!!

    [update] I just tried having Boundary inherit from `MonoBehavior` and set the values in its Start method... I expected that the values I set in that code block would override anything I had set in the Unity gui before hitting play, but that wasn't the case! The values set in gui were being used, instead.

    So how to set default public values in code which will be respected in gui?
     
    Last edited: Jul 20, 2016
  10. Ddado

    Ddado

    Joined:
    Jul 20, 2016
    Posts:
    3
    I'm getting the error: NullReferenceException: Object reference not set to an instance of an object
    I've already read a lot of solutions in this forum but none of them solved my problem, idk what to do.


    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.  
    10. public class PlayerController : MonoBehaviour {
    11.     public float speed;
    12.     private Boundary boundary;
    13.     private Rigidbody rb;
    14.  
    15.     void Start ()
    16.     {
    17.         rb = GetComponent<Rigidbody>();
    18.     }
    19.    
    20.     void FixedUpdate ()
    21.     {
    22.         float moveHorizontal = Input.GetAxis("Horizontal");
    23.         float moveVertical = Input.GetAxis("Vertical");
    24.  
    25.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    26.         rb.velocity = (movement * speed);
    27.         rb.position = new Vector3 (
    28.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    29.             0.0f,
    30.             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    31.             );
    32.     }
    33. }
    34.  
     
  11. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    if you click on the error in the console, does it indicate what line and what script is causing the issue.
    should give you a place to start looking to backtrack from.
     
  12. Ddado

    Ddado

    Joined:
    Jul 20, 2016
    Posts:
    3
    It's in the line 27:
    Code (CSharp):
    1. rb.position = new Vector3 (
    2.             Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    3.             0.0f,
    4.             Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    5.             );
    When I delete this line, the script runs fine, but I need this line, I tried to write in a lot of ways but I'm still getting the error
     
  13. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    so something in that line is NULL somewhere. and the only things that we have declared were the 'rb' for the Rigidbody and our 'boundary' instance.

    looking at your Start() method, it seems ok that you have assigned rb correctly ( and assuming that you have a RigidBody component attached to this gameobject) so lets look at boundary.

    looking at the declaration of boundary, on line 12 where you have.
    Code (CSharp):
    1. private Boundary boundary;
    this should be
    Code (CSharp):
    1. public Boundary boundary;
    try that and see if that resolves it.

    another quick way to test if a script compiles in MonoDevelop, is to go to Build > Build All, and it will highlight that very declaration line ;)
    doesnt always work, but worth a shot in most cases.
     
    Ddado likes this.
  14. Ddado

    Ddado

    Joined:
    Jul 20, 2016
    Posts:
    3
    Omg, it's working now, thanks very much, really, thanks man.
     
  15. Lasairiona

    Lasairiona

    Joined:
    Jul 21, 2016
    Posts:
    3
    Hey folks,

    I'm getting an error message when using &&, it says 'Invalid expression term', but I don't see anything wrong with it? It says the same about position in shotSpawn.position and rotation in shotSpawn.rotation. I'm very confused and have been stuck for a few days.

    I've done the roll-a-ball tutorial before this and that went great, so this is only my second attempt at Unity...

    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.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     private Rigidbody rb;
    13.  
    14.     public float speed;
    15.     public float tilt;
    16.     public Boundary boundary;
    17.  
    18.     //make shots
    19.     public GameObject shot;
    20.     public GameObject shotSpawn;
    21.     public float fireRate;
    22.  
    23.     private float nextFire;
    24.  
    25.     void Start ()
    26.     {
    27.         rb = GetComponent<Rigidbody>();
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.         if (Input.GetButton("Fire1")) && Time.time > nextFire)
    33.             {
    34.             nextFire = Time.time + fireRate;
    35.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    36.             }
    37.     }
    38.  
    39.     void FixedUpdate ()
    40.     {
    41.         //move ship
    42.         float moveHorizontal = Input.GetAxis ("Horizontal");
    43.         float moveVertical = Input.GetAxis ("Vertical");
    44.  
    45.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    46.         rb.velocity = movement * speed;
    47.  
    48.         rb.position = new Vector3
    49.             (   //ship boundaries within play area
    50.                 Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    51.                 0.0f,
    52.                 Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    53.             );
    54.  
    55.         //ship tilt when moving sideways
    56.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    57.     }
    58. }
    Thanks so much folks!
     
  16. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    Line 32 where you have currently;
    Code (CSharp):
    1.        if (Input.GetButton("Fire1")) && Time.time > nextFire)
    you have an extra bracket there as the second bracket after "Fire1" closes the if statement.

    try this and see if this works.

    Code (CSharp):
    1.       if (Input.GetButton("Fire1") && Time.time > nextFire)
     
  17. Lasairiona

    Lasairiona

    Joined:
    Jul 21, 2016
    Posts:
    3
    Thank you for your suggestion. Sadly, that wasn't the issue.

    The picture 'unity error 2' shows the message the way I had it, with the double )), and the other one with the single ). I'm not quite sure what to make of it.
     

    Attached Files:

  18. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    it was one of the parsing problems, but Looking through the errors.

    where you have declared the shotSpawn at the top, you currently have.
    Code (CSharp):
    1. public GameObject shotSpawn;
    you need to change this to
    Code (CSharp):
    1. public Transform shotSpawn;
    as position and rotation are properties of the Transform component of a gameobject.
    Just to save us having to type myGameObject.transform.position for a GameObject type instead.

    so it was generating an error as GameObject type doesnt have a position property, but the Transform component on the GameObject does.

    see how that goes.
     
  19. Lasairiona

    Lasairiona

    Joined:
    Jul 21, 2016
    Posts:
    3
    I feel so stupid now >.< I've been staring at it for days. Thanks for helping, it works now! =D
     
  20. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    no worries, shhh dont use the S word, its all good as its something that you are now aware of and watch out for down the line.
    Thats what everyones here for is to learn and help out. :)
     
  21. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    I'm doing this space shooter here and I swear the codes are identical to the codes on the tutorial (save for any changed codes because of unity version updates) and every time I start the game and blow an asteroid up my game pauses and I get this error in my window


    UnassignedReferenceException: The variable scoreText of GameController has not been assigned.
    You probably need to assign the scoreText variable of the GameController script in the inspector.
    GameController.UpdateScore () (at Assets/Assets/Scripts/GameController.cs:47)
    GameController.Start () (at Assets/Assets/Scripts/GameController.cs:19)

    I made a game object with the guitext and drag and dropped like in the video the coding comes up as nothing incorrect so I have no idea why unity seems to think something is wrong.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    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 GUIText 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. }




    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. }
     
    Last edited: Jul 24, 2016
  22. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Please, post your scripts using code tags properly.
     
  23. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Alright, I changed the format so that the code now looks like a code so can anyone tell me whats wrong? because I cannot find a thing wrong.
     
  24. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Take a look at your game controller object; in the inspector, did you assign the variable textScore? It's a public variable; you must assign it manually.
     
  25. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Hmm, I'm sure I did everything the tutorial did and even backchecked to make sure everything was fine but here I have screenshot of my game controller and such
     

    Attached Files:

  26. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    The problem doesn't seem to be in the script, since it compiles. It's been quite a while that I have done that tutorial myself. The "scoreText" that you assigned, where did you take it; from the Hierarchy view or the prefab? You must take it from the hierarchy view.
     
  27. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Yeah, where you see 'Score Text' in the hierarchy there I dragged it from there and dropped it into the inspector of Game Controller. I have not actually made it a prefab.
     
  28. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Okay. Try this:
    1. remove the script from the game object,
    2. save your project and your scene,
    3. quit Unity and relaunch it,
    4. attach the script again to the object.
    Maybe you have a corrupted files somewhere. :)
     
  29. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    I deleted the game controller script from game controller object, saved both, relaunched and attached it all again but to no avail it continues to pause my play and give me the error V_V Hmmmm, this is very confusing
     
  30. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    The exact same error? Word for word?

    All right; I dug out my old project and attached your game controller script to my game controller; filled the variables and played: it's official, your script is clean. The problem must be with the text object.

    Now try filling the scoreText variable this way:

    Sans titre-1.jpg
     
    Last edited: Jul 25, 2016
  31. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    So I did the assigning like in the image and tested it again and I got the same error again.


    UnassignedReferenceException: The variable scoreText of GameController has not been assigned.
    You probably need to assign the scoreText variable of the GameController script in the inspector.
    GameController.UpdateScore () (at Assets/Assets/Scripts/GameController.cs:47)
    GameController.Start () (at Assets/Assets/Scripts/GameController.cs:19)

    the way i make my GUI text is
    1) create empty game object
    2) create gui text in it's inspector then rename everything to Score Text

    Hmmm, this has me extremely stumped.
    I'll put some pictures of the way things are in my inspector maybe somewhere in there lies an issue.

    Also worth noting I played my game before adding the GUI and the extra coding and it played fine however after, this keeps happening. And when I look on google for help everyone has changed their GUI Text to a UI Text

    The only other thing I can think of is to ignore it and finish the tutorial which completes the scripts to look like the 'done' scripts and hope that fixes it but I highly doubt it XD otherwise I'm at a loss @_@
     

    Attached Files:

    Last edited: Jul 25, 2016
  32. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    You must have overlooked something at some point. Leaving things as they are and use the "done" stuff won't help you learn anything. Forget about web searches, everything you need is in the videos.

    I had a similar problem with the Survival Shooter tutorial once; I trashed it; entirely remade it and, this time, everything went well. Also, modifying things in the tutorial instead of simply following the instructions Adam gives us in the videos is a bad idea; better do the tutorial exactly as explained in the videos and then adapt it to your own tastes. ;)
     
  33. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    I have been doing that and where that does sound possible I may have overlooked something it can't be because I followed the the instructions played and paused haha, looked at both scripts and everything is the same XD it had to of happened within the one video because I did follow his instructions and right at this last bit I'm stuck. I guess I'll go over the video that introduced this and go through it once again. re look at the audio video and the one after I guess because nothing is incorrect. Unless its a discrepancy with the unity version he used and the one im using o_O

    Also even this person was having issues as well, same as me

    http://answers.unity3d.com/questions/804735/project-space-shooter-cant-assign-variable-scorete.html
     
    Last edited: Jul 25, 2016
  34. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Did you try what the poster did? Adding:

    Code (CSharp):
    1. using UnityEngine.UI;
    and then

    Code (CSharp):
    1. scoreText = GetComponent <Text> ();
    in the Start function? This should work.
    ___________________________​

    All these problems are weird. I made this tutorial with Unity 5.3.4f1; the scripts are exactly the ones Adam dictated in the videos; I just opened it in 5.3.5f1; I didn't get any update message from the API updater and it works perfectly, without any error messages.
     
    Last edited: Jul 25, 2016
  35. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Nope, I put using Unity Engine.UI under the two at the top and it said it was unnecessary so I ignored it and put under Void Start and on top of score:0 the second code and it said it cannot implicitly change UI to GUI. X__X Thank you for helping me with this, I bet you are going just as crazy as I am. I've asked Adam and my course trainers for help also haha I think we need to start a think tank :p Everything I look into tells me to change it to UI instead but it worked in the tutorial that I followed so I'm definitely not changing.
     
  36. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Add it anyway; that's how the guy fixed his problem. :)
     
  37. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Jarryd,

    Any chance you could zip up your project and pop it online, just so we can download for a looksee.

    doesnt seem like theres anything glaring to me either at first look and Ladyonthemoon has been through quite a bit with you to try and resolve. the GUIText although a different approach and superceeded by the Unity UI system should still work as explained in the tute and the upgrade guide.

    if you can zip the folder and pop it online, Im curious for a look ;)
     
  38. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    So I decided to scrap what I did before but it looks like it half fixed my issue, now it doesn't pause it plays fine but the errors come up where as before it would pause everytime I destroyed an asteroid but I have put up a Zip of my game to see if anyone can see what I cannot XD
     
  39. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Where is it?

    By the way, what version of Unity are you using?
     
    Last edited: Jul 26, 2016
  40. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
  41. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    We need to create an account out there to access your file...
     
  42. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Unfortunately yes, though I thought everyone had a dropbox these days since it made it easy to move around large files. It's what I use to send my submissions into my course trainers and such. I tried here but if I try inside this comment the limits 4mb and I'm not truly sure how to use this website since I made an account because of this problem haha XD
     
  43. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Jarryd,

    thats the URL just to load the dropbox page and your subfolder while youre logged in unfortunately.

    when in dropbox and you have the list of folders hover over the folder you want to share, you need to click the Share button on the right that pops up.
    the next box, change it to 'Can View' then click the little blue link for 'Copy Link' and then you can share the link as its then copied into your clipboard so you can paste it back here :)
     
  44. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    https://www.dropbox.com/s/4n0f1ivcqh3rtjt/Vertical Shooter.zip?dl=0

    Hopefully that links correctly

    and I'm using UNITY ver. 5.3.5f1

    I just did the sharing and the link on dropbox, I was afraid it would do something like that >_> But this time it should work

    Sorry again guys, I to appreciate the time you're both putting into help me though.
     
  45. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    It's a little tricky but I managed to download it. :) I just took a look into the archive; you should get rid of the "done" folder, it being here is a call for troubles. ;)

    Okay, I took a look at your project and found nothing. Since it works anyway, I suggest that you carry on and see what happens in the future. :)
     
    Last edited: Jul 27, 2016
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    @Jarryd7786 Ive just finished going through it.

    one thing to try and get in the habit of early on is organising your folders in a structure that makes sense to you, as it will save you alot of time trying to remember where things are.
    I did notice that you have a projectSettings folder in there too, was that imported from another project? As far as im aware this belongs in the parent project folder and not the assets, but you had one there so I just deleted this one.

    OK, so the problem you are getting, took me a while to find it, but if you look on your Asteroid explosion prefab, you have a GameManager script accidentally attached to it. remove that script and try again, should be ok.
     
  47. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    It would never have occurred to me to look there!.. I think the problem is solved now.
     
  48. Jarryd7786

    Jarryd7786

    Joined:
    Jul 24, 2016
    Posts:
    17
    Are you serious!!! D= my prefab had a wrong script!!! I looked over that like ten times! XD I cannot believe this. And yeah you are right. I have no idea why assets has other project settings inside it since I never from my knowledge did anything like that at all but I'll try this and get back. haha I cannot believe it.

    UPDATE: THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU XD it worked I have no earthly idea why that script was there. No more doing this late at night now. Thank you again you two for putting up with me and troubleshooting. Now my mind is at ease and time to get me my diploma back on track ^_^
     
    Last edited: Jul 27, 2016
    OboShape likes this.
  49. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    aye it was a bit of an obscure one, just ended up following the chain of events and checking objects/components along the way.

    You can also pause the game, go to the script in the project window. right click the script and find dependencies in the scene and they show up there. but was a bit more awkward in this case as the explosion prefab is destroyed after 2 seconds.
     
    Last edited: Jul 27, 2016
  50. Mishkawy

    Mishkawy

    Joined:
    Feb 17, 2016
    Posts:
    7
    Hi everyone,
    Great tutorial.

    Problem:
    everything is working perfectly, and I get no error messages, however, the Enemy Spaceships do not fire their bolts, but strangely, there are bolts that I can see being fired by themselves from the middle of the screen along with the enemy fire audio.
    In other words, enemy ships do not fire, but there are bolts firing from one single point along with audio but the shots are coming from nowhere.

    I don't think there is a problem with the scripts as I followed step by step, and I tried my best in comparing between my scene and the prefabs in the "done scene".

    Any help will be highly appreciated. space shooter problem.jpg