1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. Unity 5.6 is now released.
    Dismiss Notice
  3. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    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,545
    You should swap to WebGL in the Build Settings Window:
    Screen Shot 2017-04-20 at 10.34.24.png

    Then, using the [Player Settings...] button open the Player Settings (or use the main menu selection).

    Screen Shot 2017-04-20 at 10.34.47.png

    The player settings should have resolution and default templates, etc..
     
  2. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    <snip>

    We had not (have not?) covered structs at this point, and we have covered classes, so we used classes.

    I see what you're doing with Update, but if it were me, I would still use a coroutine unless a coroutine just didn't work for my project.

    [edit]

    Now, that being said, there are some very good uses of Update for controlling things like waves. There is a trade off, where Update is called every frame, and too many stray Updates can decrease performance. Now, there are some issues with Coroutines, especially uncontrolled Coroutines. If you feel that you need to use an Update loop, I would probably split it off into a wave controller and not have it mixed with Input detection, etc.

    But that's my opinion.
     
    Last edited: Apr 20, 2017 at 10:53 AM
  3. davhaqsg

    davhaqsg

    Joined:
    Thursday
    Posts:
    4
    Hi Unity Support,

    I am new to game development. But have some background in programming.

    I am trying to build on the Space Shooter to make it a Co-op game. 2 players on the same screen side by side.
    I believe I have the Player controls figures out by just updating the Input Manager settings and duplicating the PlayerController script to PlayerController2 and update that.

    The problem I am having is that I can't get the logic to work for the Game Over.
    Since now there are 2 players Coop, both players must die before Game Over can be true.

    I believe I should be editing the DestroyByContact script for this to work, but, no luck.

    Appreciate the advice.

    Thx.
    davhaqsg
    Unity Game Developer NOOB
     
  4. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    Are you trying to make a coop 2 players 1 keyboard game? Or are you using multiplayer networking?

    I'm afraid without more details, we can't help.

     
  5. SaadSerious

    SaadSerious

    Joined:
    Apr 3, 2017
    Posts:
    1
    hi guyz,
    im having an error Cannot find 'GameController' script after adding enemy ship to the hazards list,also the game hangs after 30 secounds
     
  6. Sty2000

    Sty2000

    Joined:
    Friday
    Posts:
    1
    hey, i'm having trouble making the fire 1 key work to create the bolts my code is

    void update() {
    if (Input.GetButton("Fire1") && Time.time > nextFire)
    {
    nextFire = Time.time + fireRate;
    Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    }

    with nextFire being a private float and fireRate being a public float as well as having the prefab and the spawner object inserted to their respective slots in the script what am i doing wrong here?
    edit: found it, i forgot an uppercase letter in Update
     
    Last edited: Apr 21, 2017 at 9:10 PM
  7. davhaqsg

    davhaqsg

    Joined:
    Thursday
    Posts:
    4
    Hi Adam,

    I am setting up the Coop game on 1 keyboard, 2 players using the WASD and IJKL keys. Setup is in Unity Input Manager.
    So far, player control, firing and maneuvring of the 2 player ships, are working independently.

    Thx,
    davhaqsg
     
  8. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    Don't forget that C# is CaSe SeNsItIve!

    There is no unity callback called "update"!

    Use "Update" instead - with the Capital U.

     
  9. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    Can you give us any more information? What script is it that cannot find the GameController? Do you have a game controller to find? Do you have any other run time errors? Can you post the code of the script that's failing to find?
     
  10. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    I would probably split out the "game over" logic and put it into the game controller script. I'd then have each player call the game controller to end the game.

    You may also need a "disable" player ship function that gets called when the game is over, as one ship dying will end the game and you'll need to disable the other ship.

    Or you'll need to detect that both ships are destroyed before the game is over.
     
  11. davhaqsg

    davhaqsg

    Joined:
    Thursday
    Posts:
    4
    Hi Adam,

    Noted. I will try splitting the Game Over function.

    Thx.
    dahaqsg
     
  12. davhaqsg

    davhaqsg

    Joined:
    Thursday
    Posts:
    4
    Hi Adam,

    Your advice worked. I got the Space Shooter on 2 players Coop, single game window, same keyboard.
    Separate Scores and Game Over for each player.

    Thanks for the directions.

    Now I having issues after building the game to PC Standalone, the game is minimized.
    I can hear the audio and keys are working, but, I cannot maximize the game.

    Pls see screenshots for reference.

    1) Build for PC Standalone Windows x86 with 1 scene.
    Build_issue_screenshot1.PNG

    2) Configuration screen after launching Space_Shooter_Game.exe. I just clicked on Play!
    Build_issue_screenshot2.PNG ,

    3) Game is minimized in Windows taskbar. Audio and Keys working.
    Build_issue_screenshot3.PNG

    Thx again,
    davhaqsg
     
  13. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    827
    just looking at the configuration screen, the monitor select doesnt appear to have anything in it.
    is there anything in that monitor select dropdown? just to specify the target display.

    I think as default in Windows anyhoo, any DirectX or OpenGL build, once focus is lost it minimises.
    if its Windows Does ALT-TAB ing select the running application back into focus?
     
  14. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    Huh... Never heard or seen this...

    I noticed that in the screen shot the "select monitor" is blank... could it be that it's not finding your monitor? I also believe in player settings (you can get to this from either the main menu or from the player settings button on the build window) you can set the game to "full screen" - but I could be making that up. That's where you'd set the default screen settings, iirc.

    If this persists, let me know.
     
  15. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    Heh - cross post! What he said!
     
    OboShape likes this.
  16. peanutbuttertate

    peanutbuttertate

    Joined:
    Monday
    Posts:
    1
    Hey Adam, awesome tutorial, thank you!

    I've tried searching through this thread and can't seem to find anything on the subject but how do I make the asteroids bounce into one another? I've tried everything, from adjusting mass, to using AddForce (although I don't think I'm doing it right.) I noticed in the first part of extending the space shooter, the enemy ship bounced into an asteroid and moved another direction before you applied the destroyByContact script to it. However in my version of the game, asteroids move through one another and even newly added 3D objects. I've even tested it against the Final game. My sense is that it has something to do with the Mover script but I'm feeling a little lost.

    Thanks!
     
  17. S_Squire

    S_Squire

    Joined:
    Monday
    Posts:
    3
    I'm having issue moving vertically, went ahead and added the clamp and tilt code, it works fine moving horizontally just does not respond to up or down arrow

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]
    6. public class Boundry
    7. {
    8.     public float xMax, xMin, yMax, yMin;
    9. }
    10.  
    11. public class PlayerController : MonoBehaviour
    12. {
    13.     private Rigidbody rb;
    14.     public float speed;
    15.     public float tilt;
    16.     public Boundry boundry;
    17.  
    18.     private void Start()
    19.     {
    20.         rb = GetComponent<Rigidbody>();
    21.     }
    22.  
    23.     private void FixedUpdate()
    24.     {
    25.         float moveHorizontal = Input.GetAxis("Horizontal");
    26.         float moveVertical = Input.GetAxis("Vertical");
    27.        
    28.         Vector2 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    29.         rb.velocity = movement * speed;
    30.  
    31.         rb.position = new Vector3
    32.             (
    33.             Mathf.Clamp (rb.position.x, boundry.xMin, boundry.xMax),
    34.             0.0f,
    35.             Mathf.Clamp (rb.position.y, boundry.yMin, boundry.yMax)
    36.             );
    37.  
    38.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    39.     }
    40. }
    I did get an error on unity console saying something like the ends of my lines were not uniform but its disappeared since progressing to adding the tilt and clamp coding
     
  18. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    First off, the way the hazards are spawned, they should never ever touch each other. They all move at the same rate, they are spawned a few seconds apart and they are spawned from different locations along the spawn line. The only way they could conceivably touch each other is if you've adjusted one of the spawn or speed parameters.

    If you want the asteroids to bounce off each other you need to change the trigger colliders into physics colliders by deselecting "isTrigger". You will then need to readjust the code detecting collisions, as "OnTriggerEnter" will no longer work. You should look in the manual about physics, physics colliders and "OnCollisionEnter".


     
  19. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    Unity can work with / ignore different line endings. Mac and Win operating systems use different characters to end a line (there are carriage returns, line feeds and what not) but Unity doesn't care. I assume that since all/most coding applications warn you, someone must care - just not Unity.
     
  20. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,545
    I don't see anything obvious with your code.
    So - then we should look for assigned variables!
    - Could your boundary on the vertical (y axis) be set to 0? Or have the numbers beackwards? eg yMin is + and yMax is - ?
    - Could you have rewritten or overwritten your "Vertical" axis in the Input Manager?
     
  21. Mickee27

    Mickee27

    Joined:
    Sunday
    Posts:
    4
    Hi There,


    I am having an issue with creating my bolt. I have followed the script and I have tried starting it again in Unity following the instructions but when I go to test my bolt it doesn't move on the screen.

    I have attached a screenshot and also the code below if anyone could help.

    upload_2017-4-25_21-33-10.png

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mover : MonoBehaviour
    6. {
    7.     private Rigidbody rb;
    8.  
    9.     public float speed;
    10.  
    11.     void Start()
    12.     {
    13.         rb.velocity = transform.forward * speed;
    14.     }
    15.  
    16. }
    17.  
     
  22. S_Squire

    S_Squire

    Joined:
    Monday
    Posts:
    3
    Thanks for the prompt reply :)

    I've tried flipping the clamp range as it was an issue on the horizontal initially (was flickering at the edges of the screen) but that didn't sort it.
    Checked the input manager and it appears to have the vertical named vertical and the rest seems to match up with my horizontal entry, beyond looking at the input manager to check the name strings not touched it
     
  23. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    248
    Mickee27,

    I think you need to get your Rigidbody component.

    Add to your Start() method rb=GetComponent<Rigidbody>(), make it the first line in your method and see if that helps.
     
    OboShape likes this.
  24. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    248
    s_squire,

    check line 28 on the code you have posted. Is that Vector2 supposed to be a Vector3?
     
    OboShape likes this.
  25. Mickee27

    Mickee27

    Joined:
    Sunday
    Posts:
    4
    Yes that did the trick thank you for your help :)
     
    Adam-Buckner likes this.
  26. S_Squire

    S_Squire

    Joined:
    Monday
    Posts:
    3
    You glorious b*st*Rd! Cheers for that
     
    Adam-Buckner likes this.