Search Unity

Space Shooter Tutorial Q&A

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

  1. Deleted User

    Deleted User

    Guest

  2. Twisted_Code

    Twisted_Code

    Joined:
    Mar 6, 2019
    Posts:
    3
  3. Deleted User

    Deleted User

    Guest

    No idea at all. All the tutorials are here anyway: https://unity3d.com/learn/tutorials
     
  4. shane4roofie71

    shane4roofie71

    Joined:
    Feb 20, 2019
    Posts:
    5
    upload_2019-3-10_11-45-17.png

    iv only just started the script and im getting errors thrown help please
     
  5. Tuan-Le473

    Tuan-Le473

    Joined:
    Apr 19, 2015
    Posts:
    1
    Code (CSharp):
    1. Rigibody rigibody;
    2. void Start()
    3. {
    4. rigibody = Getcompoment<Rigibody>();
    5. ........
    6. }
    It will work.
     
  6. quinzel12

    quinzel12

    Joined:
    Feb 27, 2019
    Posts:
    2
    Me too! Thanks for the update!
     
  7. horatioflash2007

    horatioflash2007

    Joined:
    Dec 7, 2018
    Posts:
    1
    I have one error for the restart function (Ending the game)
    Error 1. Keyword void cant be used in this context
    here's my code

    void Start()
    {
    gameOver = false;
    restart = false;
    restartText.text = "";
    gameOverText.text = "";
    score = 0;
    UpdateScore();
    StartCoroutine (SpawnWaves());
    }

    IEnumerator SpawnWaves()
    {
    yield return new WaitForSeconds(startWait);

    void Update()
    {
    if (restart)
    {
    if (Input.GetKeyDown(KeyCode.R))
    {
    Application.LoadLevel(Application.loadedLevel);
    }
    }
    }




    while (true)
    {

    for (int i = 0; i < hazardcount; i++)
    {
    Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    Quaternion spawnRotation = Quaternion.identity;
    Instantiate(Hazard, spawnPosition, spawnRotation);
    yield return new WaitForSeconds(spawnWait);
    }
    if (gameOver)
    {
    restartText.text = ("Press 'R' for Restart");
    restart = true
    break;
    }
    yield return new WaitForSeconds(waveWait);

    }
    }

    public void AddScore (int newScoreValue)
    {
    score += newScoreValue;
    UpdateScore();
    }

    void UpdateScore()
    {
    scoreText.text = "score: " + score;
    }

    public void GameOver()
    {
    gameOverText.text = "Game Over";
    gameOver = true;
    }

    }
     
  8. unity_nOdYnMD6mmhwgQ

    unity_nOdYnMD6mmhwgQ

    Joined:
    Mar 20, 2019
    Posts:
    2
    Hi I am stuck on lesson shooting shots, following the tutorial updated my player-controller script, but when I hit play and click to fire the bolts seem to be stuck right in front of the player ship and doesn't travel forward. I can see more bolts piling on top of the existing shots and non moves forward. when I drag the prefab bolt into the scene it move forward as expected. Any idea on where I might have gone wrong ?

    here is my player-controller script:

    using UnityEngine;
    using System.Collections;
    [System.Serializable]
    public class Boundary
    {
    public float xMin, xMax, zMin, zMax;
    }
    public class PlayerController : MonoBehaviour
    {
    public float speed;
    public float tilt;
    public Boundary boundary;
    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
    private float nextFire;
    void Update ()
    {
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
    nextFire = Time.time + fireRate;
    Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    }
    }
    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");
    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    GetComponent<Rigidbody>().velocity = movement * speed;
    GetComponent<Rigidbody>().position = new Vector3
    (
    Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
    0.0f,
    Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    );
    GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    }
    }
     
  9. unity_nOdYnMD6mmhwgQ

    unity_nOdYnMD6mmhwgQ

    Joined:
    Mar 20, 2019
    Posts:
    2
    hi again, I have moved on to the next tutorial boundary, it seems that the Shots are moving and being destroy by the bounding box but I can't see it move, it just stays in front of the ship until it gets destroy. Any clue is to why I can't see the shots animated forward ?

    Thanks!
     
  10. afridi14641

    afridi14641

    Joined:
    Oct 28, 2018
    Posts:
    2
    thank you very much for your help God Bless you always
     
  11. wechat_os_Qy06ZZHcb9FF3mcv7mD-ZlrIc

    wechat_os_Qy06ZZHcb9FF3mcv7mD-ZlrIc

    Joined:
    Mar 29, 2019
    Posts:
    1
    When I start the Space Shooter ,there is a error existing.And I can not realise the meaning of it.
    MethodAccessException: Method `UnityEditor.Analytics.AnalyticsSettings:get_enabledForPlatform ()' is inaccessible from method `UnityEditor.Analytics.AnalyticsImporter:<AnalyticsImporter>m__6 (UnityEditor.BuildTarget,System.Collections.Generic.HashSet`1<string>)'
    UnityEditor.Build.BuildDefines.GetScriptCompilationDefines (BuildTarget target, System.String[] defines) (at D:/unity/Modules/BuildPipeline/Editor/Managed/BuildDefines.cs:20)
    UnityEditorInternal.InternalEditorUtility:GetCompilationDefines(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget, ApiCompatibilityLevel)
    UnityEditorInternal.InternalEditorUtility:GetCompilationDefines(EditorScriptCompilationOptions, BuildTargetGroup, BuildTarget) (at D:/unity/Editor/Mono/InternalEditorUtility.cs:424)
    UnityEditor.Scripting.ScriptCompilation.EditorCompilationInterface:GetTargetAssembliesWithScripts()
     

    Attached Files:

  12. itrion

    itrion

    Joined:
    Mar 16, 2018
    Posts:
    1
    I was getting the exact same issue but I solved by upgrading unity. Actually, there were more than 400 errors related to that analytics stuff and all those just gone by upgrading :)
     
  13. NoahPoirier2407

    NoahPoirier2407

    Joined:
    Mar 1, 2019
    Posts:
    1
    Hey how do i make the game 3d?
     
  14. DripDrop1

    DripDrop1

    Joined:
    Mar 17, 2019
    Posts:
    5
    -----------------------------------------------------
    ---------------------------------------------------------------------------------------------

    Hi, in regards to unity_nOdYnMD6mmhwgQ's problem, I have the same problem and the same code as well at the same spot in the Space tutorial. I've also tried declaring the Rigidbody class variable as
    ---------
    public Rigidbody rigidbody;

    and implementing

    rigidbody.rotation = Quaternation.Euler( ... etc.

    instead of

    GetComponent<Rigidbody>().rotation = Quaternation.Euler(... etc.


    ---------------------------
    for example.

    While this compiles, the problem is not fixed.

    In the tutorial, rigidbody is built into Unity without the need for a Rigidbody deceleration. Do you know why this is, and if this has something to do with the problem. At the moment I haven't any idea other than this.

    Also, are you getting your ship to move and to tilt with this script because I am not? Thanks.
     
  15. T-Winters-

    T-Winters-

    Joined:
    Apr 4, 2019
    Posts:
    1
    So i am having an issue on 07 of the tutorial shooting shots..
    so i got the code right as far as i can tell and it will fire when i want it to fire and i have "shot spawn" as a child for player
    but it wont follow my ship.. it will continue to shoot from the transform position of 0, 0, 1.25



    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.     void Start()
    14.     {
    15.         rb = GetComponent<Rigidbody>();
    16.     }
    17.     public float speed;
    18.     public float tilt;
    19.     public Boundary boundary;
    20.  
    21.     public GameObject shot;
    22.     public Transform shotspawn;
    23.     public float fireRate;
    24.  
    25.     private float nextFire;
    26.  
    27.     void Update()
    28.     {
    29.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    30.         {
    31.             nextFire = Time.time + fireRate;
    32.             //          GameObject clone =
    33.             Instantiate(shot, shotspawn.position, shotspawn.rotation); // as GameObject;
    34.         }
    35.     }
    36.     void FixedUpdate()
    37.     {
    38.         float moveHorizontal = Input.GetAxis("Horizontal");
    39.         float moveVertical = Input.GetAxis("Vertical");
    40.  
    41.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    42.         rb.velocity = movement * speed;
    43.  
    44.         rb.position = new Vector3
    45.         (
    46.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    47.             0.0f,
    48.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    49.         );
    50.  
    51.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    52.     }
    53. }
    So i figured it out under the player controller script in the inspector view i must not of dragged "Shot Spawn" onto the shotspawn location to tell unity "Hey shoot from here" -_- well sleep does wonders lmao
     
    Last edited: Apr 5, 2019
  16. DripDrop1

    DripDrop1

    Joined:
    Mar 17, 2019
    Posts:
    5
    ------------------------------------------------------
    Post Status: Issues Resolved.

    So the issues I was having are sorted out now. Inside my PlayerController script, I was calling Fixed Update() as a nested call inside of the Update() call because I had my brackets out of sorts. I have the space ship moving and shooting though the shots couldn't be seen, because the quad sprite clones of Bolt were appearing orthogonal to the camera screen on the trigger press button call. So I redid that and fixed some other problems and now everything is functioning as it ought to.
     
  17. daniilbcross101

    daniilbcross101

    Joined:
    Apr 21, 2019
    Posts:
    1
    What do i do if the platform web player in the build settings isn't there?
     
  18. Deleted User

    Deleted User

    Guest

    The web player has been deprecated a long time ago. You must build for WebGL instead. :)
     
  19. Abellacy

    Abellacy

    Joined:
    Apr 3, 2019
    Posts:
    2
    Hello people. I know this tutorial is from time ago, but i just ended it succesfully. Except for one thing.
    When it comes to the part of building the game, I´ve set the resolution on a round 600x900 as the tutorial says.
    And it looks well on Game View. I also noticed the scale is set to 0.66 whenever I put that resolution as in the tutorial.

    upload_2019-5-16_3-59-36.png


    So does that scale have something related with the fact that, when I build the project with that resolution setting, the game looks zoomed on my default browser? Like this, in browser it only shows the Game Over Text, the upper part of the screen is cut off. But if I put the browser size on 67%(which i dont think it´s necessary at all) it shows up perfectly.

    upload_2019-5-16_4-5-59.png

    Anyone got a clue about how this happens or how to fix it? I´m interested on learning about UI so I can improve it on my games. Thanks in advance!!!
     
  20. CJLopez

    CJLopez

    Joined:
    Aug 26, 2013
    Posts:
    1
    Hi there, I have been following this tutorial and was about to finish it, when I had to format my computer. Once I restored it, I installed by mistake the alpha version of Unity and running the project on the alpha version, well, weird behaviours started to pop.

    I was able to get most of them working as they should except 1 thing, somehow, my ship, when reaching the boundary, gets out of the play area


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class playerMovement : MonoBehaviour
    6. {
    7.     public float speed = 0.0f;
    8.     public float tilt;
    9.     public Boundary boundary;
    10.  
    11.     void FixedUpdate ()
    12.     {
    13.         float moveHorizontal = Input.GetAxis("Horizontal");
    14.         float moveVertical = Input.GetAxis("Vertical");
    15.  
    16.         var movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    17.         var rigidBody = GetComponent<Rigidbody>();
    18.         rigidBody.velocity = movement * speed;
    19.  
    20.         rigidBody.position = new Vector3
    21.             (
    22.                 Mathf.Clamp(rigidBody.position.x, boundary.xMin, boundary.xMax),
    23.                 0.0f,
    24.                 Mathf.Clamp(rigidBody.position.z, boundary.zMin, boundary.zMax)
    25.             );
    26.  
    27.         //rigidBody.rotation = Quaternion.Euler(0.0f, 0.0f, rigidBody.velocity.x * -tilt);
    28.     }
    29.  
    30. }
    31.  
    32. [System.Serializable]
    33. public class Boundary
    34. {
    35.     public float xMin, xMax, zMin, zMax;
    36. }
    What I had found its that, the ship is moved out of the killBox area

    upload_2019-8-10_17-31-12.png
    Player left outside of the play are by the KillBox
    upload_2019-8-10_17-35-20.png

    This "killBox" es what I use to remove object that reach to it in order deactivate them in case they didn't collision with something else (an enemie, a bullet)

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class KillBox : MonoBehaviour
    5. {
    6.     void OnTriggerExit(Collider other)
    7.     {
    8.         Debug.Log(other.gameObject.name);
    9.         switch (other.gameObject.tag)
    10.         {
    11.             case "Bullet":
    12.                 //Debug.Log("A bullet reached the killbox");
    13.                 other.gameObject.SetActive(false);
    14.                 break;
    15.             case "Enemie":
    16.                 //Debug.Log("An Enemy reached the killbox");
    17.                 other.gameObject.SetActive(false);
    18.                 break;
    19.             default:
    20.                 Debug.Log($"{other.gameObject.transform.parent.gameObject.name} reached the killbox");
    21.                 break;
    22.         }
    23.     }
    24. }
    Previous to using an alpha version, it wasn't giving me this behaviour. I'm currently on 2019.2.0f1

    Making the killBox huge, well, this problem is no longer present, but then again, another one appears. If I enable the killBox box collider, the vertical movement is redenred slow, like, turtle slow. It moves like ignoring the speed modifier, until I also add horizontal movement, it moes normally

    Any idea on why is this happening?
     
    Last edited: Aug 11, 2019
  21. goprajakta

    goprajakta

    Joined:
    Aug 1, 2019
    Posts:
    1
    GUIText is not available in unity....only 3D text is available.......what else to use instead of that.... As GUIText is used in script also.....

    upload_2019-8-20_14-34-18.png
     
  22. xZare

    xZare

    Joined:
    Dec 15, 2019
    Posts:
    3
    Does anyone know how to spawn waves in a formation, like the most space shooter games today?
     
  23. NickNack66

    NickNack66

    Joined:
    Jul 28, 2018
    Posts:
    1
    Is it possible to find the original Space Shooter assets somewhere? I'm trying to teach a class with this tutorial but the other free packs on the asset store have a lot of unnecessary features that get in the way a bit.
     
  24. LelandGreen

    LelandGreen

    Joined:
    Oct 6, 2017
    Posts:
    13
    Looks like the tutorial has been "archived". (Which I'm guessing removes it from all searches, unless you have the URL, *or* search the archive? I've not yet looked into my theories.;))

    I had to google the tutorial, which is still online, with assets, here:
    https://learn.unity.com/project/space-shooter-tutorial/?tab=materials

    Good luck and best regards.
     
  25. Spike-n-Art

    Spike-n-Art

    Joined:
    Dec 26, 2019
    Posts:
    1
    I Enrolled on a course at Udemy that requires me to download the Space Shooter Assets however they are no longer available, is there another way to acquire these?
     
  26. LelandGreen

    LelandGreen

    Joined:
    Oct 6, 2017
    Posts:
    13
    Dear Spike-n-Art,

    They've just been archived. (Apparently.) I googled the tutorial and I found this on this unity page, and sure enough there's a link to download it. However, it doesn't say "download". Underneath "Project Materials", click the link that says, "Space Shooter Asset Package"

    Here's the page with all original files intact:
    https://learn.unity.com/project/spa...6.1207864526.1577433549-1792668676.1539256790

    Best regards,
    Leland…
     
    christh likes this.
  27. Urbanwarfare-Std

    Urbanwarfare-Std

    Joined:
    Jan 6, 2013
    Posts:
    33
    rangis0810 likes this.
  28. unity_17081986telefon

    unity_17081986telefon

    Joined:
    Apr 1, 2020
    Posts:
    1
  29. LelandGreen

    LelandGreen

    Joined:
    Oct 6, 2017
    Posts:
    13
    My apologies. You're correct. When I followed my link above, it leads to a "404" on the asset page.

    @unity_17081986telefon, not sure, but I think you can you open two projects and then either copy/paste drag/drop between them, can't you?

    Best of luck,
    Leland...
     
  30. SamuelJM

    SamuelJM

    Joined:
    Mar 10, 2018
    Posts:
    1

    Attached Files:

    Last edited: May 10, 2022
    christh likes this.