Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Space Shooter Tutorial Q&A

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

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Well, that doesn't sound good. Can you load your project into the editor and then submit a bug from the in editor bug reporter (I believe it's under the help menu) and this should submit your project along with your report. Then you'll receive an email with the report number. Can you get me that number? Thanks!
     
  2. Sloan57

    Sloan57

    Joined:
    Mar 5, 2016
    Posts:
    7
    Done !
    (Case 777782) simultaneous actions
    I have forgotten to tell you how to reproduce the issue: it's simply, you need to test the game in a android device.
    I have built my project for android and it created a file with extension .apk and I dragged this file on my phone and I have installed the game. Then just lauch the game.
     
  3. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    That was first that I did but it didn't work too :(
     
  4. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    What's not working about it?

    Can you please post the details of your problem?

    We need enough information to be able to know what your issue is, exactly, to be able to solve it.

    Please write a complete and accurate description of your problem and include any relevant supporting material, such as screen captures and code snippets.

    Please display any images in-line so we can see them easily and post any code snippets using code tags. (How to use code tags: http://forum.unity3d.com/threads/using-code-tags-properly.143875/)
     
  5. jlj170384

    jlj170384

    Joined:
    Mar 5, 2016
    Posts:
    10
    Found it after a couple of hours! there was a space where there shouldn't have been! all working great!

    Do you have a tutorial on implementing a pause/restsart?

    Thanks
     
  6. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    solved:) thanx for your time anyway and one more for the tutorial:)
     
  7. TrueGhostshark

    TrueGhostshark

    Joined:
    Mar 7, 2016
    Posts:
    1
    I'm wondering why the game controller isn't working and not spawning in asteroids even though i have followed your directions exactly and I have checked to see what is wrong but to no avail so can you help me out.
     
  8. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    I am developing Space Shooter project.
    I have some problems. I hope that you will solve it or show me a way to solve it.
    I added an object. When the object collides with the Player, sound must Play. But, it is not working.
    The object has Audio Source component. And this script attached.

    See source code below:

    private AudioSource pickUp;

    void Start ()
    {
    pickUp = GetComponent<AudioSource> ();
    }

    void OnTriggerEnter(Collider other)
    {
    if ( other.CompareTag("Player"))
    {
    pickUp.Play ();
    gameController.AddGiftScore ();
    Destroy(gameObject);
    }
    }


    Problem is in the OnTriggerEnter function because If pickUp.Play () in the Start function, it is working. And other function calls are working in the OnTriggerEnter. Only pickUp.Play () is not working.
    In addition, When pickUp.Play () in the Update function, it is playing . However, it is not working in OnTriggerEnter function.
     
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning, are you getting any error showing in the console at all?

    Can you post your gamecontroller script please so we can have a wee looksee (if you can use code tags please when posting code)
     
  10. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    If you have a look at how Adam does it within the space shooter, he creates a gameobject for the explosion and its corresponding SFX, which is separate to the enemy etc, its sole function is to show a nice explosion and play a sound.

    One thing to try, if you comment out the Destroy(gameObject), do you notice any difference in the sound playing?
    (just note that the object isnt being destroyed though)

    Following the logic of what you have there;
    1) Starts playing a soundclip in the audiosource on the object.
    2) Adding a score.
    3) Destroying the current game object.

    So what is probably happening is your sound clip starts playing coming from the AudioSource on your object.
    you then update the score, and then mark the object to be destroyed at the end of the frame.

    At the end of the current frame, the object will be destroyed along with its AudioSource which is currently playing the sound and thereby stopping your sound in its tracks.

    So for a solution you can try and implement a similar approach as Adam done with the explosions by instantiating an object that solely caters for the SFX, or have your Player manage the collecting of pickups and playing of the SFX .

    or have a look at PlayClipAtPoint, which may cover what you are looking for as an alternative.
    http://docs.unity3d.com/ScriptReference/AudioSource.PlayClipAtPoint.html
     
    Last edited: Mar 10, 2016
  11. Roug

    Roug

    Joined:
    Mar 10, 2016
    Posts:
    1
    I've built my Space Shooter, it works great in project, but it is not opened in any browser. (Unity Web Player is installed)
    Unity Version 5.3.2.
    Is a problem that Unity doesn't support Web Player anymore or what?

    P.S. Sorry for dumb questions.
     
    Last edited: Mar 10, 2016
  12. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hi @Roug
    No such thing as a dumb question bud, ask away :)

    If youre looking to deploy to the web, try the WebGL Platform.

    As of the end of last year Chrome removed NPAPI plugin support completely, which affected the Web Player plugin for chrome, to test you will have to find a browser out there with NPAPI support, cant think of one off the top of my head im afraid :(

    Looks like as of 5.4 the web player plugin platform will be removed from being a deployement platform (build selection). (from what ive read, apologies if thats incorrect)

    Have a little read through the blog posting relating to the future of web builds and Unity, will give a more indepth view on whats happening.
    http://blogs.unity3d.com/2015/10/08/unity-web-player-roadmap/
     
  13. Felix_M

    Felix_M

    Joined:
    Feb 28, 2016
    Posts:
    11
    Yeah haha in learning that now. Thank you for taking the time to answer individual questions man. Kinda trippy to see the guy who was teaching the tutorials replying xD
     
  14. iceblizzz

    iceblizzz

    Joined:
    Mar 11, 2016
    Posts:
    1
    Hello everyone i'm net to gamedev an was foloowing the tutorials on the learn page. I'm currently trying the space shooter tutorial and I'm at the extended part. now i get this error in my script that I can't solve if anyone can help me out that would be great. Btw i'm using Unity version 5.3. I've tried using the Done scripts and copy and paste the contents from those files into mine but that doesn't work.

    Here is the error i get: Assets/Scripts/DestroyByContact.cs(42,24): error CS1061: Type `GameController' does not contain a definition for `AddScore' and no extension method `AddScore' of type `GameController' could be found (are you missing a using directive or an assembly reference?)

    Thank in advance.
     
  15. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening, is AddScore the same spelling and case in your GameController script as well as your DestroyByContact script?
    Just in case the function name is not spelled and capitialised exactly the same as the function you are trying to call.

    if thats not it, can you post the two scripts for your GameController and DestroyByContact please.
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    There is a live training session where we implement a pause window.
     
  17. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please post the details of your problem?

    We need enough information to be able to know what your issue is, exactly, to be able to solve it.

    Please write a complete and accurate description of your problem and include any relevant supporting material, such as screen captures and code snippets.

    Please display any images in-line so we can see them easily and post any code snippets using code tags. (How to use code tags: http://forum.unity3d.com/threads/using-code-tags-properly.143875/)
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    How to use code tags: http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  19. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    Hello !
    I've just finished the space shooter tutorial and it was really fun. Thanks a lot !!
    We enjoy this game with my 7 years old daughter, especially when i shoot bolt enemy in the wrong direction ! ( before using Enemy tag).
    Well, we can validate that the explosion enemy works fine .
    I'm asking myself three questions before beggining another tutorial.

    1. How can i implement an ´autofire' var on the player ?
    I want to put it to '0' to avoid shooting without doing Tap tap tap tap ! on the button.
    I know i can ajust the firerate to do this but i want to do it with a variable.

    2. Bolt and bolt enemy disappear when touching each other.
    Is there a way to avoid this?

    3. When i fire a bolt to the left or to the right, the bolt disappear regarding the tilt value of the player. No issue when the player is static or tilt value =0. Can we fix it ?

    Thank you in advance !
     
  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Well - we try to give the full-meal-deal here! It's my pleasure, and I'd rather support the lessons we make, so everyone can move on as quickly as possible.

    Also - we have great help! Folks like @OboShape really do a great job!
     
    OboShape likes this.
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yes, this is most likely the case. The error may seem to come from DestroyByContact script and you could copy and paste the DestroyByContact code, but the actual problem is probably in the GameController script. The DestroyByContact script is looking for a function called AddScore (spelled and capitalized exactly like that, and if it's anything different (eg: if it's addScore, addscore or any other combination the code), then the DestroyByContact script won't be able to find it.
     
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    If you want the ship continuously when holding the button down then you would need to make sure the shooting is using if (Input.GetButton("Fire1")) rather than if (Input.GetButtonDown("Fire1")).

    If you want the ship to fire continuously all the time, then you need to set that up in the Update function and remove the if (Input.GetButton("Fire1")) and just have it fire regularly based on fireRate.

    To prevent the bolts from colliding with each other, you will either need to use the physics collision layer matrix or you will need to adjust the tags being checked.

    The bolts disappearing if the player is tilted is an issue because when the ship is tilted, the bolts will fire based on that tilt and go either up or down off of the game plane and be destroyed by the boundary, which is fairly thin. The solution for this is to separate the spawn points from the tilt. You'd need to have the spawn points be children of the root player GameObject, so they didn't tilt, and then tilt the model, and not the root GameObject. To do this, take a reference to the model and apply the tilt to the model, not to the root GameObject.
     
  23. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    Thank you Adam for your quick answers !
    I will try your tips this weekend and give you a feedback as soon as possible.
     
  24. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    I just solved my first issue :
    1. Autofire !!
    My goal was to add a variable 'autofire'.
    By 'autofire' i mean (yes i know that it was before the era of tablets :) )

    Autofire = 1
    When i let 'Ctrl' down, the bolt is fired continually at the firerate value.

    Autofire = 0
    When i let 'Ctrl' down, the bolt is fired... once.
    You have to retry tapping 'Ctrl' to fire another bolt.
    The firerate value is almost needed in that case if you want to deal with the number of bolts. (i have set it to 0.1, it works fine.)

    So I edit the PlayerController.cs by adding a public bool :
    It add a checkbox 'autofire' in the inspector.
    Code (CSharp):
    1.  public bool autoFire;
    and modify the Update() and create a Shot() :
    Code (CSharp):
    1.  void Update()
    2.     {
    3.         if (autoFire == true)
    4.        {
    5.             if (Input.GetButton("Fire1") && Time.time > nextFire)
    6.             {
    7.                 Shot();
    8.             }
    9.        }
    10.       else
    11.         {
    12.             if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
    13.             {
    14.                 Shot();
    15.             }
    16.         }
    17.     }
    18.  
    19.     void Shot()
    20.     {
    21.         nextFire = Time.time + fireRate;
    22.         foreach (var shotSpawn in shotSpawns)
    23.         {
    24.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    25.             audioSource.Play();
    26.         }
    27.     }
    Is there a way to change the 'autofire' value by taking a bonus in the game ?
     
    Last edited: Mar 11, 2016
    drfever likes this.
  25. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Nice one for getting that done :)

    what are you looking to have as a bonus? if its a thing you pickup, or score based?

    at the crux of it, it boils down to "if bonus criteria is met, then set autofire to true"

    in the case of a pickup, you could use a similar approach to triggers as you have done with the bullets (as in the OnTriggerEnter), so when the player collides with the shiny powerup you can set autofire to true.

    but really depends on what bonus criteria you decide upon and what your next steps would be.
     
  26. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    Thx OboShape.
    You have understand that i wanted to do.
    In fact, i use unity for 2 weeks now (just the space shooter tutorial to be honest).
    I have a lot of ideas in my mind but not a real project at the moment.
    I prefer learn basic actions even if it's a long way rather declare :
    ' I'm doing the greatest shmup in earth !' :)

    By the way, i solved the point 2 :
    why 'bolt' and 'bolt enemy' disappear when colliding ?

    Add a layer 'bolt' to both bolt prefabs and uncheck the box (bolt/bolt) in the layer collision matrix !!
     
  27. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    for only 2 weeks your doing fantastic (waay better than i did), keep it up!

    ideas are great, chip away at each new "what if i do this....." that springs to mind :)

    and if you get to a hurdle, these forums are fantastic, a wealth of knowledge and people more than glad to share it.

    and keep having fun doing it, sounds like you are.. so brill :)
     
  28. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    I solved 2 of 3 issues.
    But, i'm still bothered by the tilted bolts.

    I'm not sure to know what is the difference between 'root player object' and 'the model'
    So, I don't understand how to do this.
    My last try shoot lateral bolts fine but from the center of the screen :)
    Could you give me more details ?
     
  29. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    The root player object is the gameobject that is called player and should hold all of the details about the player, including the player model. Then model should be a child object that holds the artwork (mesh) of the spaceship.
     
  30. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    Sorry Adam, i still not be able to do with your method...
    But now, I can shot 3 bolts which aren't affected by the tilt value.
    I was worried because i bypass the shotspawns ! Weird...

    Shotspawns are a best pratice for extended projects (mandatory or not ??)

    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.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.  
    16.     public GameObject shot;
    17.     //public Transform shotSpawn;
    18.     //public Transform[] shotSpawns;
    19.  
    20.     public bool autoFire;
    21.     public float fireRate;
    22.  
    23.     private float nextFire;
    24.  
    25.     private Rigidbody rb;
    26.     private AudioSource audioSource;
    27.  
    28.  
    29.     void Start()
    30.     {
    31.         rb = GetComponent<Rigidbody>();
    32.         audioSource = GetComponent<AudioSource>();
    33.     }
    34.  
    35.     void Update()
    36.     {
    37.         if (autoFire == true)
    38.        {
    39.             if (Input.GetButton("Fire1") && Time.time > nextFire)
    40.             {
    41.                 Shot();
    42.             }
    43.        }
    44.       else
    45.         {
    46.             if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
    47.             {
    48.                 Shot();
    49.             }
    50.         }
    51.     }
    52.  
    53.  
    54.    // void Shot()
    55.     //{
    56.        // nextFire = Time.time + fireRate;
    57.         //foreach (var shotSpawn in shotSpawns)
    58.        // {
    59.             //Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    60.            // audioSource.Play();
    61.         //}
    62.    // }
    63.  
    64.  
    65. void Shot()
    66.     {
    67.         nextFire = Time.time + fireRate;
    68.             Instantiate(shot, transform.position, Quaternion.Euler(0, 0, 0));
    69.             Instantiate(shot, transform.position, Quaternion.Euler(0, 20, 0));
    70.             Instantiate(shot, transform.position, Quaternion.Euler(0, -20, 0));
    71.         audioSource.Play();
    72.     }
    73.  
    74.     void FixedUpdate()
    75.     {
    76.         float moveHorizontal = Input.GetAxis("Horizontal");
    77.         float moveVertical = Input.GetAxis("Vertical");
    78.  
    79.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    80.        rb.velocity = movement * speed;
    81.  
    82.         rb.position = new Vector3
    83.             (
    84.                 Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    85.                 0.0f,
    86.                 Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    87.                 );
    88.  
    89.         rb.rotation = Quaternion.Euler(0.0f ,0.0f , rb.velocity.x * -tilt);
    90.  
    91.     }
    92. }
     
    Last edited: Mar 13, 2016
  31. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Your solution works. You need to put in a Quaternion for a spawn rotation. By hard coding the numbers you have less flexibility to change these values and more difficulty getting them correct, but it works.
     
  32. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    Finally, i found a solution.
    Your response to xoxoroxo page 28 helps me. (it takes me half of the afternoon :) )
    Thank you for your patience !

    So, this line was very useful :

    Code (CSharp):
    1.  Instantiate(shot, shotSpawn.position, Quaternion.Euler(0.0f, shotSpawn.rotation.eulerAngles.y, 0.0f));
    The full code below, if it can helps somone else...
    I notice that when tilt is set to 4 -> no problem (visually).
    When it is set to 10, the angle of lateral shots is almost the same like the main bolt.
    But they still stay in the game area.

    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.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.  
    16.     public GameObject shot;
    17.     public Transform[] shotSpawns;
    18.  
    19.     public bool autoFire;
    20.     public float fireRate;
    21.  
    22.     private float nextFire;
    23.  
    24.     private Rigidbody rb;
    25.     private AudioSource audioSource;
    26.  
    27.  
    28.     void Start()
    29.     {
    30.         rb = GetComponent<Rigidbody>();
    31.         audioSource = GetComponent<AudioSource>();
    32.     }
    33.  
    34.     void Update()
    35.     {
    36.         if (autoFire == true)
    37.        {
    38.             if (Input.GetButton("Fire1") && Time.time > nextFire)
    39.             {
    40.                 Shot();
    41.             }
    42.        }
    43.       else
    44.         {
    45.             if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
    46.             {
    47.                 Shot();
    48.             }
    49.         }
    50.     }
    51.  
    52.  
    53.      void Shot()
    54.     {
    55.       nextFire = Time.time + fireRate;
    56.      foreach (var shotSpawn in shotSpawns)
    57.     {
    58.       Instantiate(shot, shotSpawn.position, Quaternion.Euler(0.0f, shotSpawn.rotation.eulerAngles.y, 0.0f));
    59.      audioSource.Play();
    60.      }
    61.     }
    62.  
    63. void FixedUpdate()
    64.     {
    65.         float moveHorizontal = Input.GetAxis("Horizontal");
    66.         float moveVertical = Input.GetAxis("Vertical");
    67.  
    68.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    69.        rb.velocity = movement * speed;
    70.  
    71.         rb.position = new Vector3
    72.             (
    73.                 Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    74.                 0.0f,
    75.                 Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    76.                 );
    77.  
    78.         rb.rotation = Quaternion.Euler(0.0f ,0.0f , rb.velocity.x * -tilt);
    79.  
    80.     }
    81. }
    Could you advice me another tutorials to learn making shmups ?
     
    Last edited: Mar 13, 2016
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Great! I'm glad you got that working. Sadly, we don't have many more lessons on schmups. There is scrolling backgrounds and object pooling in the live training archives - all of which can help.
     
  34. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    I have already seen the tuto for scrolling background. I'm asking how to manage the time. My goals with bg scrolling are :
    - choose when it start (delay for introduction at the beginning of a level)
    - reduce and add speed at wanted areas
    - making a loop at mid-boss and last boss.
    - changing tiles during the level.

    I need to learn also object pooling which is as i know fundamental for shmup game.

    And also learn to make waves, enemy movements and attacks :)
    Hard to be a newbee !!
    Maybe you have some topics, shmup's group on unity forum (or useful functions in documentation) to help me regarding shmups ?
     
  35. Crasius

    Crasius

    Joined:
    Mar 14, 2016
    Posts:
    3
    Hello everyone! I've got an error when I was finishing the project. This is the error in the console (Thank you very much in advance. I've been trying to figure it out by myself for the last 3 days with no success)

    Assets/Scripts/DestroyByContact.cs(34,40): error CS1061: Type `GameController' does not contain a definition for `GameOver' and no extension method `GameOver' of type `GameController' could be found (are you missing a using directive or an assembly reference?)

    This is the DestroyByContact script:

    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.             gameController.GameOver ();
    35.         }
    36.         gameController.AddScore (scoreValue);
    37.         Destroy(other.gameObject);
    38.         Destroy(gameObject);
    39.     }
    40.        
    41. }
    42.  
    And here is the GameController script:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    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 Text scoreText;
    15.     public Text restartText;
    16.     public Text 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.         StartCoroutine (SpawnWaves  ());
    29.         score = 0;
    30.         UpdateScore ();
    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.  
    44.     IEnumerator SpawnWaves ()
    45.     {
    46.         yield return new WaitForSeconds (startWait);
    47.         while (true)
    48.         {
    49.             for (int i = 0; i < hazardCount; i++)
    50.             {
    51.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    52.                 Quaternion spawnRotation = Quaternion.identity;
    53.                 Instantiate (hazard, spawnPosition, spawnRotation);
    54.                 yield return new WaitForSeconds (spawnWait);
    55.             }
    56.             yield return new WaitForSeconds (wavewait);
    57.  
    58.             if (gameOver)
    59.             {
    60.                 restartText.text = " Press 'R' for Restart";
    61.                 restart = true;
    62.                 break;
    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 GameObver ()
    79.     {
    80.        
    81.         gameOverText.text = "Game Over!";
    82.         gameOver = true;
    83.     }
    84. }
    85.  
     
  36. 9uile

    9uile

    Joined:
    Mar 11, 2016
    Posts:
    32
    Look at your line 78. You have too much 'b'
     
  37. Crasius

    Crasius

    Joined:
    Mar 14, 2016
    Posts:
    3
    OMG I am embarrassed. lol Thank you so much for your help. I really appreciate it.
     
  38. Mazer83

    Mazer83

    Joined:
    Mar 14, 2016
    Posts:
    19
    At 1:34 he says to import the assets for this project. What assets? Where do I get them from?
     
  39. phamtq

    phamtq

    Joined:
    Mar 8, 2016
    Posts:
    6
    The last part of Lesson 1:5 Moving the Player was very interesting to me and made something in my mind 'click'. The part where you type:

    Code (CSharp):
    1. rb.rotation = Quaternion.Euler (0.0f, 0.0f, rb.velocity.x * -tilt);
    makes me think it's a cool way to rotate things using 3 axis (easy to do and understand) with a 4 axis system (x, y, z, w) that prevents gimbal-lock. If you can output the value of 'w', I bet this would be a good way to teach physics to people. Unity, more than just a way to make games. Very cool.
     
  40. phamtq

    phamtq

    Joined:
    Mar 8, 2016
    Posts:
    6
    Go to the Menu, Window, and Asset Store. Search for Space Shooter and the assets should be available for download into your project (and future projects).
     
  41. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Hello brothers and sisters,
    I am so grateful to all of you. I am happy to learn Unity3d with you due to the fact that you always reply quickly. Thank you.

    I have one more question. I have developed Space Shooter project.
    There are 3 public methods in my GameController script. See below:

    public int lighting;
    public int protection;
    public int life;

    public GUIText protectionText;
    public GUIText lifeText;
    public GUIText lightingText;


    public void AddProtectionScore()
    {
    protection++;
    ShowProtectionScore ();
    }

    public void AddLightingeScore()
    {
    lighting++;
    ShowLightingScore ();
    }

    public void AddLifeScore()
    {
    life++;
    ShowLifeScore ();
    }

    public void ShowProtectionScore()
    {
    protectionText.text = "Protection: " + protection;
    }
    public void ShowLightingScore()
    {
    lightingText.text = "Lighting: " + lighting;
    }
    public void ShowLifeScore()
    {
    lifeText.text = "Life: " + life;
    }

    I will explain what I am going to do with these methods. There are three extra gameObjects in game which are life, lighting and protection. Player is capable of collecting these game objects. When Player collide with them, Player will have an ability. I did all well.

    But, in my opinion, it is not optimal approach because I have 3 Adding method which has to do same work.
    In addition, 3 Showing methods have to do same work. Only variable which is inside of the method is different.
    Maybe inheritance can solve this problem? I am not sure. I cannot apply it to this problem.

    Can you suggest another optimal approach?
     
  42. BlackBat023

    BlackBat023

    Joined:
    Feb 9, 2016
    Posts:
    14
    Ok I've seems to have fixed this now... I just played around with the enemyship prefabs' child object's rotations and managed to fixed it that way. Thanks for the advise. :)
     
  43. rashid597

    rashid597

    Joined:
    Feb 24, 2016
    Posts:
    3
    When I press "R" to restart, my scene's lighting changes to dark.Please help!
     
    Last edited: Mar 16, 2016
  44. lildobber13

    lildobber13

    Joined:
    Mar 16, 2016
    Posts:
    1
    EDIT: I just checked back and apparently I only have one error which is:

    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:18)

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     private Rigidbody rb;
    7.  
    8.     void start()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.     void FixedUpdate ()
    13.         {
    14.             float moveHorizontal = Input.GetAxis("Horizontal");
    15.             float moveVertical = Input.GetAxis("Vertical");
    16.  
    17.             Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    18.             rb.velocity = movement;
    19.         }
    20. }
    21.  
    22.  
    UPDATE: I just realized Start wasn't capitalized, it works great now. Silly mistake.
     
    Last edited: Mar 16, 2016
  45. Gollam

    Gollam

    Joined:
    Mar 16, 2016
    Posts:
    1
    Hi There!

    I am working on #11 - Game Controller. Everything has worked up to this point, but I cannot get the asteroid to spawn at a random location. I am not getting any errors, it just always spawns in the center.

    I have even tried to comment out my script and copied in the code provided below the video, same result.

    Here is my code:

    upload_2016-3-16_10-1-50.png
    And here is a screenshot of my Inspector:

    upload_2016-3-16_10-2-11.png

    EDIT - Nevermind. I re-watched the video and realized that in the inspector I forgot to set my X spawn value to 6. It is working now :)
     
    Last edited: Mar 16, 2016
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    if memory serves, i had something to do with this, and i ended up baking the lights. I think this was patched it a later release, have you updated to the latest unity version?
     
  47. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    I am developing Space Shooter project. So I need to apply inheritance to my code. Can you recommend some tutorials explaining inheritance in Unity3d. I know about inheritance but i never see it in real time project. I need some example projects using inheritance.
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have you had a look through the 2D RogueLike tutorial Matt done? or even in the scripting tutorials section.

    Looking through any of the C# or OOP tutorials related to inheritance out in thee interweb should give you some pointers.
     
    Last edited: Mar 18, 2016
  49. Kangasaur

    Kangasaur

    Joined:
    Mar 18, 2016
    Posts:
    3
    Hi,
    I was going through the Space Shooter tutorial, and was on the Boundary assignment. I went through everything the tutorial said; however, the bolts being shot were still not destroyed. I made sure that both the Boundary's and the Bolt's colliders were triggers, and I am pretty sure that my code is exactly like that in the tutorial:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByBoundary : MonoBehaviour
    5. {
    6.     void OnTriggerExit(Collider other)
    7.     {
    8.         Destroy(other.gameObject);
    9.     }
    10. }
    11.  
    What is interesting is that there is a script error in Unity, both for my code, and the Done version:
    Script Error: OnTriggerExit
    This message parameter has to be of type: Collider

    Thanks for the help in advance! I really don't know what's wrong here.
     
  50. Impostor Studios

    Impostor Studios

    Joined:
    Mar 11, 2016
    Posts:
    1
    how would I make the asteroids spawn on the y axis instead of on the x?
    i tried writing it like this:
    (spawnValues.x(- spawnValues.y, spawnValues.y) spawnValues.z);
    but i get an error saying unexpected symbol 'spawnValues'

    But when I use this:
    (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    it works fine, but i need the asteroids to spawn on the y axis
    I was creating my own project but needed to know how to spawn waves so I used your tutorial. please help.