Search Unity

Space Shooter Tutorial Q&A

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

  1. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    Show the code you have, you probably missed something on DestroyOnBoundary script
     
  2. Ryanb360

    Ryanb360

    Joined:
    Sep 13, 2018
    Posts:
    1
    Hey everyone I keep getting:
    Assets/Lobby/Scripts/Lobby/LobbyManager.cs(266,59): error CS0030: Cannot convert type `UnityEngine.Networking.PlayerController' to `PlayerController123'
    I have read the most common fix was to change public class PlayerController : MonoBehaviour to something else so I changed it to public class PlayerController123 : MonoBehaviour

    here is a copy of my code because I am still getting the same error.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController123 : MonoBehaviour
    6. {
    7.     private Rigidbody rb;
    8.  
    9.     private void Start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.  
    14.     private void FixedUpdate()
    15.     {
    16.     float moveHorizontal = Input.GetAxis("Horizontal");
    17.     float moveVertical = Input.GetAxis("Vertical");
    18.  
    19.     Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    20.     rb.velocity = movement;
    21.     }
    22. }
    23.  
     
  3. harshdulani

    harshdulani

    Joined:
    Sep 3, 2018
    Posts:
    6
    here
     using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class DestroyOnContact : MonoBehaviour
    {
    void onTriggerEnter(Collider other)
    {
    if (other.tag == "Boundary") {
    return;
    }
    Destroy (other.gameObject);
    Destroy (gameObject);
    }
    }


    please do tell me if i should show you any other script files/anything
     
  4. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    Not destroyonContact,

    DestroyOnBoundary ... with the OnTriggerExit Function or you could remove the return in this function but idk how its setup in the tutorial
     
  5. harshdulani

    harshdulani

    Joined:
    Sep 3, 2018
    Posts:
    6
    im sorry. here this is the destroybyboundary function.

    here is the tutorial web page
    https://unity3d.com/learn/tutorials/projects/space-shooter-tutorial/creating-hazards?playlist=17147

    Code (CSharp):
    1. public class DestroyByBound : MonoBehaviour {
    2.  
    3.     void OnTriggerExit(Collider other)
    4.     {
    5.         // Destroy everything that leaves the trigger
    6.         Destroy(other.gameObject);
    7.     }
    8. }
    9.  
     
  6. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    Check that the Collider attached to the Boundary Object is sounding the area, so any object that exit it will be removed.
     
    harshdulani likes this.
  7. harshdulani

    harshdulani

    Joined:
    Sep 3, 2018
    Posts:
    6
    hey these are my inspector windows for all the GameObjects i thought would be relevant. please tell me if theres something wrong with them or i should provide with more information...
    asteroid parent.PNG asteroid prop.PNG boundary.PNG
     
  8. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    307
    How your boundary object looks like in the scene? is it big enough to be over the play area ?
     
    harshdulani likes this.
  9. harshdulani

    harshdulani

    Joined:
    Sep 3, 2018
    Posts:
    6
    here is how the the boundary object looks like, i guess yes it is big enough? scene mode.PNG

    game mode.PNG
     
  10. harshdulani

    harshdulani

    Joined:
    Sep 3, 2018
    Posts:
    6
    thanks for trying to help man. i grew impatient and deleted the Boundary and Asteroid object and started both afresh.
    everything works now ^__^
     
  11. Boromir_2014

    Boromir_2014

    Joined:
    Jun 7, 2018
    Posts:
    5
    Thanks you! I can't understand how I missed a spelling error like this one… But now it works
     
  12. hardcoredarksky

    hardcoredarksky

    Joined:
    Jun 13, 2018
    Posts:
    2
    I'm having difficulty getting the score to display. I know the GUI Text has been replaced. I am using the regular text field. I have my text rotated at 90 degrees on the X Axis. None of the text is displaying. Any suggestions or something I'm missing? Thanks!
     
  13. fernandojose2005

    fernandojose2005

    Joined:
    Sep 29, 2018
    Posts:
    2
    Hoa si aigen me responde si me puede enviar los comandos para que un personaje se mueva con W A S D plis si aigen sabe
     
  14. fernandojose2005

    fernandojose2005

    Joined:
    Sep 29, 2018
    Posts:
    2
    sie responde plis para crear un juego porfavor
     
  15. unity_j8vhEYDk-5hhug

    unity_j8vhEYDk-5hhug

    Joined:
    Sep 26, 2018
    Posts:
    2
    Hello all!

    I am new to unity and all of a sudden have encountered this error? I have uninstalled everything and deleted the projects to start a fresh and straight away upon creating the PlayerController script i get this error still.

    This happens if i create an empty project inserted a game object and attaching a script to that as well.

    Does anyone know why this is happening it is driving me insane lol!

    Thanks in advance!
     

    Attached Files:

  16. unity_792567

    unity_792567

    Joined:
    Oct 1, 2018
    Posts:
    1
    Hello Everyone, So I'm new to unity and I'm on the "Moving the Player" part of the tutorial. I'm on the 2018 version and I'm trying to do the first part( at about 6:50 of this video
    ).

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour
    {
    private Rigidbody rb;
    public float speed;
    public Rigidbody rb;

    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }
    public class ExampleClass : MonoBehaviour
    {
    float horizontalSpeed = 2.0f;
    float verticalSpeed = 2.0f;

    void FixedUpdate()

    {

    float h = horizontalSpeed.Input.GetAxis {"Horizontal"};
    float v = verticalSpeed.Input.GetAxis {"Vertical"};

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    PlayerController.rb.velocity = (movement * PlayerController.speed);
    }
    }

    It says the "Input.GetAxis{Horizontal/Vertical}, the (moveHorizontal/vertical) part of the Vector3 movement, and rb.velocity part all have errors, can someone please explain what's wrong and what to replace it with?
    Thank you so much!
     
  17. MattLottering

    MattLottering

    Joined:
    Oct 8, 2018
    Posts:
    2
    Hi there, I am running into the same issues, how and where did you create the namespace? Sorry I am very new to this and really struggling to get over this section.

    Thank you
    Matt
     
  18. MattLottering

    MattLottering

    Joined:
    Oct 8, 2018
    Posts:
    2
    Hi all, could anyone please help, I am very new to this and struggling a bit.

    I am at section 5. Moving the player.
    I have made the adjustments to the script to work with the newer version of Unity,

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PlayerController : MonoBehaviour {
    private Rigidbody rb;
    public float speed;
    void Start ()
    {
    rb = GetComponent<Rigidbody>();
    }

    void fixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");
    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rb.position = movement * speed;
    }
    }


    But I am still getting errors.

    Assets/Lobby.Scripts/Lobby/LobbyPlayer.cs(147,56): error cs0030: Cannot convert type 'UnityEngine.Networking.PlayerController' to 'PlayerController'?

    public void CheckRemoveButton()
    {
    if (!isLocalPlayer)
    return;
    int localPlayerCount = 0;
    foreach (PlayerController p in ClientScene.localPlayers)
    localPlayerCount += (p == null || p.playerControllerId == -1) ? 0 : 1;
    removePlayerButton.interactable = localPlayerCount > 1;
    }

    And

    Assets/Lobby.Scripts/Lobby/LobbyManager.cs(267,38): error CS0103: The name 'p' does not exist in current context?

    public void OnPlayersNumberModified(int count)
    {
    _playerNumber += count;
    int localPlayerCount = 0;
    foreach (PlayerController p in ClientScene.localPlayers);
    localPlayerCount += (p == null || p.playerControllerId == -1) ? 0 : 1;
    addPlayerButton.SetActive(localPlayerCount < maxPlayersPerConnection && _playerNumber < maxPlayers);
    }

    I hope this makes sense?
    Please help if possible.

    Thank you
    Matt
     

    Attached Files:

  19. JadranD

    JadranD

    Joined:
    Oct 11, 2018
    Posts:
    1
    ...cannot start SpaceShooter...when I start game (play), I get horizon with blue sky screen and it stops ??...
     
  20. Paikan

    Paikan

    Joined:
    Oct 13, 2018
    Posts:
    4
    Hi Matt and unity_j8vhEYDk-5hhug, I had the same problem when doing this project. I assume the code you've written is in Assets/Scripts. The error occurs in Assets/Lobby/Scripts, which is a different folder, part of the original tutorial package. This 'Lobby' folder caused me a ton of problems as well and, to be honest, I don't really understand what it is for... Maybe some kind of local multiplayer.

    Since I wanted to focus on making a simple single-player version of the game to follow the tutorial, I just deleted the 'Lobby' folder, and got no more conflicts. After completing the project (and if you figure out what this folder is for) you could put it back in 'Assets'.

    So yeah, just remove the Lobby folder and everything should be good.
     
    Last edited: Oct 13, 2018
  21. Paikan

    Paikan

    Joined:
    Oct 13, 2018
    Posts:
    4
    Hi everyone. I am new to Unity and have been following the Space Shooter tutorial, up to the 'Build the Game' part, where I am noticing a small problem with my game. Here is how it looks in the Editor :
    UIEditor.png
    Both the 'Score' and 'Restart' UIText objects appear in the right position at the top-left and top-right of the screen. However, when I play the game in the browser, it looks like this :
    UIBrowser.png

    My UIText objects don't appear at the top of the screen, because it is cut off, and the browser page doesn't allow me to scroll up. And if I put the game in Full Screen, well...
    UIBrowserFullScreen.png
    Here is the score Text, at the top left of the screen, and the restart at the top right, in the black areas.
    I tried a different build, in 500x700 resolution : that allowed the browser to display the entire game screen (the top was no longer cut off), but obviously did not fix the full screen UI problem.

    In short, here is what I would like to know :
    1) Is there a way to have the game properly display the 600x900 resolution in the browser window, without having to de-zoom or decrease the resolution of the build ?
    2) Would it be possible to have the UI Canvas always fit the game screen, so that even in full screen the score and restart UIText appear over the space background and not in the black bars ?

    I would really like to know how to properly make UIs, so thank you in advance to anyone who could help me with these two issues ;). Have a nice day !
     
  22. Paikan

    Paikan

    Joined:
    Oct 13, 2018
    Posts:
    4
    Hi, you need to change a couple things :
    1. First off you shouldn't have a public Rigidbody rb and another private Rigidbody rb. You only need a private one, that you correctly assign in the Start() function.
    2. Your FixedUpdate() function is wrong. It should be like this :
    Code (CSharp):
    1. void FixedUpdate(){
    2.         float moveHorizontal = Input.GetAxis("Horizontal");
    3.         float moveVertical = Input.GetAxis("Vertical");
    4.  
    5.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    6.  
    7.         rb.velocity = movement * speed;
    8. }
    9.  
    Input is a class in UnityEngine, that contains several methods including GetAxis. In your code you try to call the GetAxis method on horizontalSpeed and verticalSpeed, which are both float values, a basic C# numerical type that has nothing to do with the Unity Input interface. Simply call
    Code (csharp):
    1.  Input.GetAxis("Horizontal");
    (same with Vertical) and put the return values in your two float variables.

    Also, when calling a method, you have to give it parameters with parentheses, and not braces : write Input.GetAxis("Horizontal"); and not Input.GetAxis{"Horizontal"}; like you did.

    Finally the PlayerController.rb.velocity is wrong. PlayerController is a C# script, it does not have a rigidbody attribute. The player does, however, and since rb holds the reference to the rigidbody component of the player object, just write : rb.velocity = movement * speed;

    I hope this helped, tell me if there is something you didn't understand in my answer, or if you encounter a different problem !
     
    Last edited: Oct 13, 2018
  23. Deleted User

    Deleted User

    Guest

    This project has been updated to 2018.2 and expanded. Unfortunately the added things interfere with the tutorial as it is on the site. Removing the following directories from the downloaded project (or not importing them at all) seems to fix the problem (for now):
    • Lobby,
    • SampleScenes
    I hope this is useful to all new Unity users who are following this tutorial (and this has not been posted yet, I haven't read everything in this thread). :)
     
  24. DrAwesomeXD

    DrAwesomeXD

    Joined:
    Nov 18, 2017
    Posts:
    2
    Hi everyone,

    just starting out with Unity,
    quick Question to
    Creating shots - 06

    The tutorial says to use the Z-Axis for the capsule collider. Yet, if I use the Z-Axis with the same values, my collider looks like this: upload_2018-10-14_12-21-0.png


    It only seems to look right, if I use the Y-Axis:

    upload_2018-10-14_12-21-33.png


    Here are the Bolt properties:

    upload_2018-10-14_12-22-6.png

    I would really appreciate any help :)
    Cheers
     
  25. DrAwesomeXD

    DrAwesomeXD

    Joined:
    Nov 18, 2017
    Posts:
    2
    Oh... Sorry I already got it!!
    I set the Capsule Collider on the VFX-Object, not the Bolt-Object.
    It has to be the Bolt-Object!
    The VFX-Object behaved in this way because its rotated by 90 degrees on the X-Axis -.-
     
  26. Lindish

    Lindish

    Joined:
    Jul 21, 2017
    Posts:
    2
    Hi. So I've been following this series but seems today all of the tutorial videos are offline. Just wondering if they are being moved or discontinued or if it is just a technical glitch? Thanks Screenshot_2018-10-17 Audio - Unity.png

    Updated: They seem to be back up now, thankyou
     
    Last edited: Oct 17, 2018
  27. Amosen

    Amosen

    Joined:
    Oct 17, 2018
    Posts:
    1
  28. Deleted User

    Deleted User

    Guest

    Hi,

    I'm currently remaking this tutorial with Unity 2018.2.12f1 Personal and so far, so good.

    In the "Audio" video, at 5:30, it is said that we can drag the audio file onto a prefab without it being visible in the inspector (here dragging the "explosion_player" audio file onto the "explosion_player" prefab); I'm sorry to say that it doesn't work in Unity 2018.2.12f1 Personal.

    I've tried dragging other audio files onto other prefabs, same problem: dragging and dropping the audio file onto the prefab seems to work but the audio file is nowhere in the prefab afterwards but it appears in the Hierarchy, outside the player and at its position. Same thing for the asteroid.

    Edit: After launching Unity this afternoon, I got notification that a new version was available, 2018.2.13f1. After installing it, I imported the project anew and tried adding the audio files to the prefabs: same results. See images below.

    Capture.JPG

    The audio source was not added to the prefabs after dragging and dropping the audio files on them:

    Capture2.JPG

    Capture3.JPG
     
    Last edited by a moderator: Oct 18, 2018
  29. refschool

    refschool

    Joined:
    Dec 26, 2015
    Posts:
    1
    Hello, I want to access the score in GameController from PlayerController, how can I do this? thank you
     
  30. Paikan

    Paikan

    Joined:
    Oct 13, 2018
    Posts:
    4
    Hi, I've noticed that as well. It seems like they removed that feature. You can still drag the audio file to the inspector however, but they should probably update the tutorial to make that clear.

    Hi, once you've created a reference to the GameController script of the GameController object, call its AddScore method (or access gameController.score directly). I also want to point out that the tutorial does not ask you to access the score from PlayerController, but from DestroyFromContact. Anyway here is the kind of code you can use :
    Code (CSharp):
    1. // Declaring a GameController :
    2. private GameController gameController;
    3.  
    4. void Start ()
    5. {
    6. // We try to find a GameController object in the scene :
    7. GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    8.  
    9.         if (gameControllerObject != null)
    10.         {
    11.             // If we find the GameController, we keep a reference to its GameController script component
    12.             gameController = gameControllerObject.GetComponent<GameController>();
    13.         }
    14.  
    15. }
    16. // Then, wherever we want to add a value to the score :
    17. gameController.AddScore(scoreValue);  // Or if score is public : gameController.score += scoreValue;
     
    Last edited: Oct 20, 2018
  31. Deleted User

    Deleted User

    Guest

    I know that but the most worrying is that the audio files are created in the hierarchy window if we try dragging them on the prefab in the project window. It's not a removed feature, it's a problem.
     
    Paikan likes this.
  32. Xendrax

    Xendrax

    Joined:
    Oct 18, 2018
    Posts:
    3
    In the Extending Space Shooter, he shows us some options regarding shooting "sideways". He notices the shots are disappearing now and then for some reason. This is because when you move and shoot the ship is banking thus the rotation is no longer 0 so the shot is hitting the top of the boundary box and being deleted but because there is no perspective you cannot see tis (unless you look in your scene.

    I tried resetting the instantiated object to 0 on one plane and it seems to just reset it completely to shoot forward?!?! I tired on different axis to see if that was the problem (I still struggle with the global vs local - not sure which the code is doing) but all of them still made the shot that should go sideways just go up.
    So I tried NOT resetting any axis and giving it back the same values and it still shoots up so I know I am doing something wrong here!


    so I changed below (I no have 6 shotSpawners so I can do several different type of directional shots.. maybe for power up later of for different buttons for shot directions)

    Code (CSharp):
    1. Instantiate(shot, shotSpawns[4].position, shotSpawns[4].rotation); //this one shoots to the left
    2. Instantiate(shot, shotSpawns[5].position, shotSpawns[5].rotation); // this one shoots to the right
    to this

    Code (CSharp):
    1. Instantiate(shot, shotSpawns[4].position, shotSpawns[4].rotation); //this one shoots to the left still
    2. GameObject newShot = Instantiate(shot, shotSpawns[5].position, shotSpawns[5].rotation);
    3. newShot.transform.rotation = Quaternion.Euler(newShot.transform.rotation.x, newShot.transform.rotation.y, newShot.transform.rotation.z); //this should in theory do nothing? Its getting its values and putting it back in. I will eventually reset one of these to 0 to get it to stay in the boundary. This however now shoots up?!?!
    Any clues what I am doing wrong?
     
  33. Xendrax

    Xendrax

    Joined:
    Oct 18, 2018
    Posts:
    3
    Ah worked it out .. newShot.transform.rotation.x is acutally a Quaternion!!

    fixed it like this
    Code (CSharp):
    1. GameObject newShot = Instantiate(shot, shotSpawns[5].position, shotSpawns[5].rotation);
    2. Vector3 crntRot = newShot.transform.rotation.eulerAngles;
    3. newShot.transform.rotation = Quaternion.Euler( 0, crntRot.y, crntRot.z);
    This stops the X angle from changing (keeps it at =0) even if the shotspawn has been rotated around the X from the parent when 'banking' for the image. Now just need to do it to all the rest of my shotspawns!
     
  34. cbassar0

    cbassar0

    Joined:
    Oct 26, 2018
    Posts:
    2
    using System.Collections;
    using UnityEngine;

    [System.Serializable]
    public class Boundary
    {
    public float xMin, xMax, zMin, zMax;
    }

    public class PlayerController : MonoBehaviour {

    public float speed;
    public float tilt;
    public Boundary boundary;

    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    private Rigidbody rb;

    //fixed update
    private void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");
    Vector3 movement = new Vector3 (moveHorizontal,0.0f, moveVertical);
    rb.velocity = movement * speed;

    rb.position = new Vector3
    (
    Mathf.Clamp (rb.position.x, boundary.xMin, boundary.xMax),
    0.0f,
    Mathf.Clamp (rb.position.z, boundary.zMin, boundary.zMax)
    );

    rb.rotation = Quaternion.Euler (x, y, z);
    }
    }

    **************************************************************************************************************************************


    Having made these alterations for version 5, CAN SOMEONE EXPLAIN why the ASSETS Lobby manager is complaining about "player controllerId not found? NO ONE IS TALKING ABOUT THIS!!!
     
  35. Deleted User

    Deleted User

    Guest

    Having made these alterations for version 5, CAN SOMEONE EXPLAIN why the ASSETS Lobby manager is complaining about "player controllerId not found? NO ONE IS TALKING ABOUT THIS!!![/QUOTE]
    Please, use the proper tags when you post a script: https://forum.unity.com/threads/using-code-tags-properly.143875/

    The lobby might have something to do with the very last training session about creating the mobile version of the game (https://unity3d.com/learn/tutorials...onverting-space-shooter-mobile?playlist=17147).

    I had to remove the lobby directory to be able to make the tutorial.
     
    Last edited by a moderator: Oct 26, 2018
  36. MountainousK4

    MountainousK4

    Joined:
    Apr 22, 2018
    Posts:
    2
    I have a problem I hope someone can help with! We just completed section 2.2 "Creating Hazards". When the shot is fired and hits the Asteroid, the DestroyByContact script is supposed to fire and destroy both shotSpawn and Asteroid. But this is not firing, I can tell because I don't see the debug statement I entered writing to the console. The shot does get destroyed when it hits the Boundary (DestroyByBoundary script is working fine)... I have gone back and watched the Creating Shots, Shooting Shots etc... videos and rewatched the 2.2 again, but I can't see what is wrong.

    I have verified the DestroyByContact is attached to my Asteroid, and the code is the same as in the video. I'm using Unity 2017 fyi...

    Could anyone give me an idea why my DestroyByContact script is not firing?
     
  37. MountainousK4

    MountainousK4

    Joined:
    Apr 22, 2018
    Posts:
    2
    EDIT ---> Figured out my IsTrigger was not set on my Asteroid object (duh)
     
  38. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23

    Hi.
    Im a beginner to Unity but have been trough a few tutorials.
    Found this one and have started to make the game, but have run into a few problems
    In Camera and lightning. I have problem to use the new sugested values by the updated guide notes.
    When you adjust the directional light (main Light to point to the ship. It is barely visible. and it look just a black and white.

    Could the capsule collider have anything to do with it?. I kept that one when I had problems with the mesh collider. But found out later that it was OK to turn the Convex on. But did not change back again.
     
    Last edited: Nov 11, 2018
  39. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23
    Im still having problems. Have put inn all 3 lights but the surface of the model is still dark (black*)
    Tried to embed a picture of it but did not work. Followed the video and the notes with no help.
    So I'm Stuck.

    When import the assets i get this message on two of the models of the players ship.
    How do i fix it ?

    A polygon of vehicle_playerShip is self-intersecting and has been discarded.

    Edit: I solved it the hard way by start over. But stil have that last error message.
    But the black and White ship problem did not came back when i was setting up that scene again.
     
    Last edited: Nov 13, 2018
  40. DieuQT

    DieuQT

    Joined:
    Aug 23, 2018
    Posts:
    1
    Hi,

    I'm new to Unity, and have been learning a lot from these Unity Tutorials. I would really like to publish a game I created using the "Space Shooter" tutorial. I finished the tutorial, and then worked on the game further to add new game features, and what I saw to be improvements for the game. I now would like to publish the game as my own, Is that allowed? Can I publish the game as my own? Do I have the rights to do so? Are the assets, and all game material provided in the tutorial and Unity Store (Tutorial for Space Shooter) free to use, and publish?

    Any help would be appreciated! I tried to find the answer but couldn't find it, so I hope someone can help me out.

    Thanks,

    Dieu
     
  41. Taz0707

    Taz0707

    Joined:
    Oct 24, 2018
    Posts:
    1
    Hi everyone.

    I have been learning Unity using the tutorials but have run into a problem with the GUIText as it is saying obsolete in Scripts however the tutorial and updated guide does not have a fix for this issue. I am running version 2018.2.12f1.

    Any ideas how I can get my score text to show up in the game area.
    Thanks
     
  42. Deleted User

    Deleted User

    Guest

    You must first add
    Code (CSharp):
    1. using UnityEngine.UI;
    at the top of the script. Then create the text variable as:
    Code (CSharp):
    1. public Text name;
    (where name is the name given in the tutorial video).

    Then create the ui text by right-clicking in the hierarchy window, go down the list to UI and select text.

    Sans titre-1.jpg

    I think the rest is unchanged. :)
     
  43. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23
    After creating the boundary box and the code and play tested it. It works fine but i getting what look like a Unity system error, an Null Exception after i play test.
    Here is the complete details of the error

    NullReferenceException: (null)
    UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/Editor/Mono/SerializedObject.cs:26)
    UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:520)
    UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:437)
    UnityEditor.RendererEditorBase.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/Inspector/RendererEditorBase.cs:330)
    UnityEditor.MeshRendererEditor.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/Inspector/MeshRendererEditor.cs:28)

    Edit: I think i have found it. The gravity was set on the players rigidbody
     
    Last edited: Nov 15, 2018
  44. Coldbeer72

    Coldbeer72

    Joined:
    Feb 5, 2017
    Posts:
    1
    Hey All.
    Having a few drama's with getting the score text to actually do what it is supposed to.

    Followed the tutorial to the letter, but the GUItext was not adding the score when the asteroids were destroyed. After many hours searching for a solution, found a "fix" using the newer UI, but, alas, the same issue presents itself.......the score text does nothing.
    Gamecontroller and DestroybyContact scripts as they currently sit are:

    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 hazard;
    9.     public Vector3 spawnValues;
    10.     public int hazardCount;
    11.     public float spawnWait;
    12.     public float startWait;
    13.     public float waveWait;
    14.  
    15.     public Text scoreText;
    16.     private int score;
    17.  
    18.     private void Start()
    19.     {
    20.         GameObject scoreTextObject = GameObject.FindWithTag("ScoreText");
    21.  
    22.         if (scoreTextObject != null)
    23.         {
    24.             scoreText = scoreTextObject.GetComponent<Text>();
    25.         }
    26.         score = 0;
    27.         UpdateScore();
    28.         StartCoroutine (SpawnWaves());
    29.     }
    30.  
    31.     IEnumerator SpawnWaves ()
    32.     {
    33.         yield return new WaitForSeconds (startWait);
    34.         while (true)
    35.         {
    36.             for (int i = 0; i < hazardCount; i++)
    37.             {
    38.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    39.                 Quaternion spawnRotation = Quaternion.identity;
    40.                 Instantiate(hazard, spawnPosition, spawnRotation);
    41.                 yield return new WaitForSeconds(spawnWait);
    42.             }
    43.             yield return new WaitForSeconds(waveWait);
    44.         }
    45.  
    46.     }
    47.  
    48.     public void AddScore (int newScoreValue)
    49.     {
    50.         score += newScoreValue;
    51.         UpdateScore ();
    52.     }
    53.     void UpdateScore ()
    54.     {
    55.         scoreText.text = "Score: " + score;
    56.     }
    57. }
    Code (CSharp):
    1. public class DestroyByContact : MonoBehaviour
    2. {
    3.     public GameObject explosion;
    4.     public GameObject playerExplosion;
    5.     public int scoreValue;
    6.     private GameController gameController;
    7.  
    8.     private void Start ()
    9.     {
    10.         GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    11.         if (gameControllerObject != null)
    12.         {
    13.             gameController = gameControllerObject.GetComponent<GameController>();
    14.         }
    15.  
    16.         if (gameControllerObject == null)
    17.         {
    18.             Debug.Log("Cannot find 'GameController' script");
    19.         }
    20.     }
    21.  
    22.     private void OnTriggerEnter(Collider other)
    23.     {
    24.         if (other.tag == "Boundry")
    25.         {
    26.             return;
    27.         }
    28.         Instantiate(explosion, transform.position, transform.rotation);
    29.         if (other.tag == "Player")
    30.         {
    31.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    32.         }
    33.         gameController.AddScore (scoreValue);
    34.         Destroy(other.gameObject);
    35.         Destroy(gameObject);
    36.     }
    37. }
    Have gone through these multiple times, and think they are ok.......what am I missing??

    Cheers

    Beer
     
  45. PetterL68

    PetterL68

    Joined:
    Jun 26, 2018
    Posts:
    23
    I think everything works now. But have anyone discovered the problem that randomly happened when you restart the
    game quickly. The player ship explode as soon as it appears on screen. without any hazards.
    Or is it just a problem with my copy?
     
  46. jettzeong

    jettzeong

    Joined:
    Nov 5, 2018
    Posts:
    65
    Hi all, my code is not working with the following 4 errors:

    Error CS8025 Feature 'local functions' is not available in C# 4. Please use language version 7.0 or greater line 40
    Error CS8025 Feature 'local functions' is not available in C# 4. Please use language version 7.0 or greater line 46
    Error CS0106 The modifier 'public' is not valid for this item line 40 Active
    Error CS0103 The name 'UpdateScore' does not exist in the current context line 21 Active
    Any help is greatly appreciated!



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class GameController : MonoBehaviour
    6. {
    7.  
    8.     public GameObject hazard;
    9.     public Vector3 spawnValues;
    10.     public int hazardCount;
    11.     public float spawnWait;
    12.     public float startWait;
    13.     public float waveWait;
    14.  
    15.     public GUIText scoreText;
    16.     public int score;
    17.  
    18.     void Start()
    19.     {
    20.         score = 0;
    21.         UpdateScore();
    22.         StartCoroutine(SpawnWaves());
    23.     }
    24.  
    25.     IEnumerator SpawnWaves()
    26.     {
    27.         yield return new WaitForSeconds(startWait);
    28.         while (true)
    29.         {
    30.             for (int i = 0; i < hazardCount; i++)
    31.             {
    32.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    33.                 Quaternion spawnRotation = Quaternion.identity;
    34.                 Instantiate(hazard, spawnPosition, spawnRotation);
    35.                 yield return new WaitForSeconds(spawnWait);
    36.             }
    37.             yield return new WaitForSeconds(waveWait);
    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.  
    51.     }
    52. }
    53.  
     
  47. Magnox79

    Magnox79

    Joined:
    Nov 29, 2018
    Posts:
    2
    HI

    I'm trying to complete this tutorial and have become stuck on the GUIText section, the work around thats used in the annotation does not work.
    I've tried adding Component>UI>Text and that does not work either.
    I've tried adding UI as a GameObject directly and while it shows text in scene, it is blurred and illegible regardless of how I try to rotate or resize the text canvas. Doesn't show in Game.
    Yes I've tried raising it above the origin, still can not see it properly.
    Oh, even in scene, the text is always behind the background, noting I do makes it properly visible.

    Any help on this please?
     
    Last edited: Nov 29, 2018
  48. Magnox79

    Magnox79

    Joined:
    Nov 29, 2018
    Posts:
    2

    EDIT: Never mind, I figured it out.
     
  49. Deleted User

    Deleted User

    Guest

    What was the problem? Some people coming here could find your answer useful.
     
  50. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    This is very helpful.Thank you!
     
    SirCodeWarrior and nidex like this.