1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Reddit AMA with Adam Myhill on Cinemachine, Thurs July 27 - 10AM PT. More info.
    Dismiss Notice
  6. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  7. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    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,612
    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,612
    <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
  3. davhaqsg

    davhaqsg

    Joined:
    Apr 20, 2017
    Posts:
    7
    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,612
    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:
    Apr 21, 2017
    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
  7. davhaqsg

    davhaqsg

    Joined:
    Apr 20, 2017
    Posts:
    7
    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,612
    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,612
    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,612
    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:
    Apr 20, 2017
    Posts:
    7
    Hi Adam,

    Noted. I will try splitting the Game Over function.

    Thx.
    dahaqsg
     
  12. davhaqsg

    davhaqsg

    Joined:
    Apr 20, 2017
    Posts:
    7
    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:
    831
    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,612
    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,612
    Heh - cross post! What he said!
     
    OboShape likes this.
  16. peanutbuttertate

    peanutbuttertate

    Joined:
    Apr 24, 2017
    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:
    Apr 24, 2017
    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,612
    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,612
    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,612
    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:
    Apr 23, 2017
    Posts:
    5
    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:
    Apr 24, 2017
    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:
    265
    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:
    265
    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:
    Apr 23, 2017
    Posts:
    5
    Yes that did the trick thank you for your help :)
     
    Adam-Buckner likes this.
  26. S_Squire

    S_Squire

    Joined:
    Apr 24, 2017
    Posts:
    3
    You glorious b*st*Rd! Cheers for that
     
    Adam-Buckner likes this.
  27. iamfake

    iamfake

    Joined:
    Apr 14, 2017
    Posts:
    4
    GameController Script
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class gamecontroller : MonoBehaviour {
    7.  
    8.     public GameObject hazards;
    9.     public Vector3 spawnvalues;
    10.     public float startwait;
    11.     public int anotherwait;
    12.     public int hazardcount;
    13.     public int wavewait;
    14.     public  Text counttext;
    15.     public int Score;
    16.     void Start () {
    17.         Score = 0;
    18.         UpdateScore();
    19.        StartCoroutine (spawnWaves());
    20.      
    21.  
    22.     }
    23.     IEnumerator spawnWaves()
    24.     {
    25.         yield return new WaitForSeconds(startwait);
    26.         while(true)
    27.         { for(int i=0;i<hazardcount;i++)
    28.             {
    29.                 Vector3 spawnposition = new Vector3(Random.Range(-spawnvalues.x, spawnvalues.x), spawnvalues.y, spawnvalues.z);
    30.                 Quaternion spawnrotation = Quaternion.identity;
    31.                 Instantiate(hazards,spawnposition,spawnrotation);
    32.                 yield return new WaitForSeconds(anotherwait);
    33.             }
    34.         yield return new WaitForSeconds(wavewait);
    35.         }
    36.     }
    37.  
    38.     public void AddScore (int newScoreValue)
    39.     {
    40.         Score += newScoreValue;
    41.         UpdateScore();
    42.     }
    43.     void UpdateScore()
    44.     {
    45.         counttext.text = "Score : " + Score;
    46.     }
    47. }
    48.  
    DestroyOnCollide Script

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyOnCollide : MonoBehaviour {
    6.     public GameObject Explosion;
    7.     public GameObject PlayerExplosion;
    8.     public GameObject gameController;
    9.  
    10.     void Start()
    11.     {
    12.         GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    13.         if(gameControllerObject!=null)
    14.          gameController = gameControllerObject.GetComponent<GameController>();
    15.         if(gameControllerObject==null)
    16.             Debug.Log("Cannot Find GameController Script");
    17.     }
    18.     void OnTriggerEnter(Collider other)
    19.     {
    20.         if (other.tag == "Boundery")
    21.             return;
    22.         Instantiate(Explosion,transform.position,transform.rotation);
    23.         if(other.tag=="Player")
    24.             Instantiate(PlayerExplosion, other.transform.position, other.transform.rotation);
    25.         gameController.AddScore(newScore);
    26.         Destroy(other.gameObject);
    27.         Destroy(gameObject);
    28.     }
    29. }
    30.  
    These are errors that I am getting:

    All compiler errors have to be fixed before you can enter playmode!
    UnityEditor.SceneView:ShowCompileErrorNotification()

    Assets/Scripts/DestroyOnCollide.cs(14,61): error CS0246: The type or namespace name `GameController' could not be found. Are you missing an assembly reference?

    Assets/Scripts/DestroyOnCollide.cs(25,24): error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `AddScore' and no extension method `AddScore' of type `UnityEngine.GameObject' could be found. Are you missing an assembly reference?
     
  28. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,612

    I wonder what magical conversion is going on here...

    Did this not throw an error?
     
  29. Mickee27

    Mickee27

    Joined:
    Apr 23, 2017
    Posts:
    5
    Hi,

    I am hoping that some one will be able to help. I am having an issue with the audio files, the asteroid and player explosion play as soon as I enter play mode but do not react when the asteroid or ship explodes. The shots behave as the should with their audio file.

    When I drag the audio file onto the prefab it appears on the prefab but also makes the prefab appear on the hierarchy menu. The prefab in the hierarchy has the audio file attached but it doesn't keep the audio file attached in the prefab folder.

    I don't know whether this is an issue from using Unity 5.6 or if there is something wrong with my script?

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

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    iamfake,

    In line 14 of the destroybycontact script Unity is looking for a component named GameController. This would be your game controller script, which you have spelled "gamecontroller" (no caps), so it is not finding what it is looking for. This name is generated when you name your script at creation, so you don't want to change the script name, rather try changing line 14 to GetComponent<gamecontroller>(); and see if that helps any. It may solve you other errors also as I think they are related.

    I am getting ready to head into a meeting at work, so will be unavailable to help for the next few hours.
     
    Adam-Buckner likes this.
  31. gforster67

    gforster67

    Joined:
    Apr 20, 2017
    Posts:
    8
    Good Afternoon,

    I am having a problem with this tutorial. The problem is with the Game Controller script, I have followed the tutorial to the letter and for some reason I am getting errors in the code regarding referencing AddScore. the exact error is "Assets/Scripts/GameController.cs(23,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 an assembly reference?"

    I have attached my code for this script can you please assist.

    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.     public GameController gameController;
    10.  
    11.  
    12.     void OnTriggerEnter(Collider other)
    13.     {
    14.         if (other.tag == "Boundary")
    15.         {
    16.             return;
    17.         }
    18.         Instantiate(explosion, transform.position, transform.rotation);
    19.         if (other.tag == "Player")
    20.         {
    21.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    22.         }
    23.         gameController.AddScore(scoreValue);
    24.         Destroy(other.gameObject);
    25.         Destroy(gameObject);
    26.     }
    27. }
    28.  
     
  32. gforster67

    gforster67

    Joined:
    Apr 20, 2017
    Posts:
    8
    Sorry it was not the GameController script, but the DestroyByContact script.
     
  33. gforster67

    gforster67

    Joined:
    Apr 20, 2017
    Posts:
    8
    Ok I resolved my issue by completely re-doing the code for both GameController script and DestroyByContact script. Now I have another issue. According to the tutorial I should see a Score field in the Game Controller object under the Game Controller script component. I do not see this, I have verified my code and there are no errors.

    Can you please assist. Code is posted below.

    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.  
    15.     private int score;
    16.  
    17.     void Start()
    18.     {
    19.         score = 0;
    20.         UpdateScore();
    21.         StartCoroutine(SpawnWaves());
    22.     }
    23.  
    24.     IEnumerator SpawnWaves()
    25.     {
    26.         yield return new WaitForSeconds(startWait);
    27.         while (true)
    28.         {
    29.             for (int i = 0; i < hazardCount; i++)
    30.             {
    31.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    32.                 Quaternion spawnRotation = Quaternion.identity;
    33.                 Instantiate(hazard, spawnPosition, spawnRotation);
    34.                 yield return new WaitForSeconds(spawnWait);
    35.             }
    36.             yield return new WaitForSeconds(waveWait);
    37.         }
    38.     }
    39.  
    40.     public void AddScore(int newScoreValue)
    41.     {
    42.         score += newScoreValue;
    43.         UpdateScore();
    44.     }
    45.  
    46.     void UpdateScore()
    47.     {
    48.         scoreText.text = "Score: " + score;
    49.     }
    50. }
     
  34. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Line 15 you have score set to private. It needs to be public if you want to see it in the inspector.
     
  35. davhaqsg

    davhaqsg

    Joined:
    Apr 20, 2017
    Posts:
    7
    Hi OboShape,

    Found and fixed the problem. My system graphic adapters got screwed up.

    Thanks a Million.
    davhaqsg
     
    OboShape likes this.
  36. davhaqsg

    davhaqsg

    Joined:
    Apr 20, 2017
    Posts:
    7
    Hi Adam,

    Basically, setup issue on my system. All working fine now.
    I just realized there's no way to quit the game ! Going to try to create the kind of Game Menu next.

    Thanks,
    davhaqsg
     
  37. gforster67

    gforster67

    Joined:
    Apr 20, 2017
    Posts:
    8
    Good Morning,

    I have resolved all issues with Space Shooter, built it for standalone, and it works great. I was wondering is any one has added some code so that you can exit and also a High Score list where you can type your initials for High Score.
     
  38. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    831
    I dont have anything to hand, but for local games if its a PC build, you could look at using playerprefs for simplicity
    https://docs.unity3d.com/ScriptReference/PlayerPrefs.html
    or have a look at the archived training session here for more info
    https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
     
    Adam-Buckner likes this.
  39. geekomancer

    geekomancer

    Joined:
    Apr 23, 2017
    Posts:
    2
    Hi everybody!

    Thank you to Unity team for such great tutorials, and for the teacher's clear & patient speaking voice. I have a couple of questions.

    1. I want to add rotation to the ship's X field, so the ship looks cool when moving forward. The problem is that it also rotates the shots, causing them to leave the "boundary". I have tried a few things, but keep getting errors. How can I 0.0f the "shot" or "shotSpawn", so that it stays within the boundary? In PlayerController.cs:
    rb.rotation = Quaternion.Euler (rb.velocity.z * tilt * 0.25f, rb.velocity.x * tilt * 0.25f, rb.velocity.x * -tilt);

    2. I thought it might be fun to subtract points for any asteroids or ships that *leave* the boundary, but can't seem to make this work. I tried adding something like this, but couldn't get it to work. In DestroyByBoundary.cs:
    GameController.AddScore (scoreValue);

    Suggestions, please? I am new to the language, but understand (somewhat) the logic. :)

    Thanks!!
     
  40. Archivist0

    Archivist0

    Joined:
    May 1, 2017
    Posts:
    2
    Someone asked this a while back and it was never answered.

    The problem is the ScoreText and the RestartText display fine in the Unity editor Run mode, but do not display in the build. The reason that this is occurring is because of the Unity Logo Bar that is added at the bottom of the game. This logo is reducing the size of the game area by its Y size. I am unsure what exactly it is doing but the top area of the game display equivalent to the size of the Logo bar does not display on Run. I can fudge the GUITexts by setting the Y offset to -100 and they will appear. I am assuming that if I had a paid version of Unity I could simply just remove the Logo bar. I tried changing the Player Settings in the build to 100 bigger, 1000 instead of 900, but it just moved the problem up further.

    Is there an actual fix for this? or do you just lose about 100 pixels of your expected game area if you have the Logo enabled in the Build?

    Thanks.
     
  41. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    64
    I used
    if (Input.GetKey("escape")) Application.Quit();
    which will quit if the "esc" key is pressed
     
  42. davhaqsg

    davhaqsg

    Joined:
    Apr 20, 2017
    Posts:
    7
    Hi gwnguy,

    Thanks for sharing. Will try.
     
  43. Saafir

    Saafir

    Joined:
    Apr 21, 2017
    Posts:
    4
    Hi, when I build and run my game it glitches and I don't know what is wrong. Can you help me? Thank you.
     

    Attached Files:

  44. Saafir

    Saafir

    Joined:
    Apr 21, 2017
    Posts:
    4
    Hi, my game glitches when I build and run my game. It loads the game, then game splits/divides one part (top part) is partly normal. The bottom part stretches off to infinity making the player and objects so thin you can't see them, you can only see a streak of color. Glitch.PNG
     
  45. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    I have not seen anything like that before. Does everything work okay in the editor?
     
  46. Saafir

    Saafir

    Joined:
    Apr 21, 2017
    Posts:
    4
    Yes everything does work in the editor, it just doesn't work when I build and run.
     
  47. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,612
    You want to change the ship's X axis? AKA: the "pitch"? Have it nose up and nose down as it turns? I am having a hard time picturing this in my head as a rational movement. Did you want to change the Y axis? Which the "yaw"? By affecting the yaw, the ship will stay on the x-z plane...

    Be aware that this game has been created to be a 2.5D game, or so simulating a 2D style game in 3D, and and change taking the game play off the x-z plane will require a complete redesign of the mechanics and logic.
     
  48. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,612
    I have not tested. This. What is your build target?
     
  49. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,612
    Weird. Never seen this. Do you have multiple cameras or a render texture, or anything not in the tutorial? What is your build target? Does this prove true when you build and run the demo or complete level?
     
  50. Adam-Buckner

    Adam-Buckner

    Unity Technologies

    Joined:
    Jun 27, 2007
    Posts:
    5,612
    I believe score is meant to be private and you should not see score in the inspector. If you believe I'm incorrect, I need to check, so can you tell me what episode and what time code this occurs in the tutorial?