Search Unity

Space Shooter Tutorial Q&A

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

  1. PANDEMICBANDIT

    PANDEMICBANDIT

    Joined:
    Aug 31, 2015
    Posts:
    8
    Here is the game controller script:
    using UnityEngine;
    using System.Collections;

    public class Done_GameController : MonoBehaviour
    {
    public GameObject[] hazards;
    public Vector3 spawnValues;
    public int hazardCount;
    public float spawnWait;
    public float startWait;
    public float waveWait;

    public GUIText scoreText;
    public GUIText restartText;
    public GUIText gameOverText;

    private bool gameOver;
    private bool restart;
    private int score;

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

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

    IEnumerator SpawnWaves ()
    {
    yield return new WaitForSeconds (startWait);
    while (true)
    {
    for (int i = 0; i < hazardCount; i++)
    {
    GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    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);
    }
    yield return new WaitForSeconds (waveWait);

    if (gameOver)
    {
    restartText.text = "Press 'R' for Restart";
    restart = true;
    break;
    }
    }
    }

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

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

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

    But now I'm getting 2 asteroids to spawn.
    And I'm also getting this in the console:

    IndexOutOfRangeException: Array index is out of range.
    Done_GameController+<SpawnWaves>c__Iterator1.MoveNext () (at Assets/Done/Done_Scripts/Done_GameController.cs:50)
     
  2. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    ah, looking at that line 50 is
    Code (CSharp):
    1. GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    Ive also noticed that your using the script from the Done folder, as opposed to what was written during the video.
    this is an extra part that Adam had put in for some stretch goals.


    the error your getting i would think is related to this array. ensure that each element in this array has an asteroid hazard in it.
    alternatively, return to the tutorial and use a single
    Code (CSharp):
    1. public GameObject hazard;
    at the top. and drag your asteroid prefab into that on the inspector.
    then you can remove the following line
    Code (CSharp):
    1. GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    as opposed to the array, to get the core game running and return to the array once completed.

    should do it, ill have a dig further once back at my own PC

    or have i got the wrong end of the stick? have you already worked through the tute and doing the extra credit stuff?
     
  3. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    hye there i stuck in Mobile inputs

    i done as it is that in tutoril of converting space shooter to mobo

    but i got problem i cant use my virtual joy stick to move player in gamefield with my firing image.

    i only Uploading two scripts because else game is working fine.
    when i control my player and tap fire image my player goes to left side of screen.
    but when i release(Untap) my control image and try to fire then it works fine.

    plz help me out

    Code (CSharp):
    1. using UnityEngine.UI;
    2. using UnityEngine.EventSystems;
    3. using System.Collections;
    4.  
    5. public class Fire : MonoBehaviour , IPointerDownHandler,  IPointerUpHandler{
    6.  
    7.     private bool touched2;
    8.     private int pointerID2;
    9.     bool CanFire;
    10.  
    11.     void Awake(){
    12.         touched2 = false;
    13.     }
    14.  
    15.     public void OnPointerDown(PointerEventData data){
    16.         if (!touched2) {
    17.             touched2 = true;
    18.             pointerID2 = data.pointerId;
    19.             CanFire = true;
    20.         }
    21.     }
    22.  
    23.     public void OnPointerUp(PointerEventData  data){
    24.         if (data.pointerId == pointerID2) {
    25.             CanFire = false;
    26.             touched2 = false;
    27.         }
    28.     }
    29.     public bool FireFire(){
    30.         return CanFire;
    31.     }
    32.  
    33. }
    34.  
    Code (CSharp):
    1. using UnityEngine.EventSystems;
    2. using System.Collections;
    3.  
    4. public class SimpleTouchpad : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler {
    5.  
    6.     public float smoothing;
    7.  
    8.     private Vector2 origin;
    9.     private Vector2 direction;
    10.     private Vector2 smoothDirection;
    11.     private bool touched;
    12.     private int pointerID;
    13.  
    14.     void Awake () {
    15.         direction = Vector2.zero;
    16.         touched = false;
    17.     }
    18.  
    19.     public void OnPointerDown (PointerEventData data) {
    20.         // set Our StartPoint
    21.         if (!touched) {
    22.             touched = true;
    23.             pointerID = data.pointerId;
    24.             origin = data.position;
    25.         }
    26.     }
    27.  
    28.     public void OnDrag (PointerEventData data) {
    29.         // Compare Between Our Start Point And Current Point locations
    30.         if (data.pointerId == pointerID) {
    31.             Vector2 currentPosition = data.position;
    32.             Vector2 directionRaw = currentPosition - origin;
    33.             direction = directionRaw.normalized;
    34.         }
    35.     }
    36.  
    37.     public void OnPointerUp (PointerEventData data) {
    38.         // Reset Everything
    39.         if (data.pointerId == pointerID) {
    40.             direction = Vector2.zero;
    41.             touched = false;
    42.         }
    43.     }
    44.  
    45.     public Vector2 GetDirection () {
    46.         smoothDirection = Vector2.MoveTowards (smoothDirection, direction, smoothing);
    47.         return smoothDirection;
    48.     }
    49. }
     
  4. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    I haven't done the Mobile aspect of the tutorial (or any for that matter, since I was concentrating on core learning), but I will try and work through it this evening as I have just got Unity remote set up last night.
     
  5. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    So Now Where & how i can get out of it any idea?

    i m Only working on Android Development therefore it is very imp part for me...

    i cant go further away before sorting this touch problem :-(
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thanks @winxalex, I appreciate this update!

    It is true that in our early tutorials we do teach code that is more tightly coupled. We find this works very well for new users, especially those who have little or no coding experience, to get up and running fast with a lot of positive feedback by getting a simple game running. When it comes to small games, the tightly coupled structure doesn't negativley effect the project. We find that as people build larger and larger projects and gain more and more coding experience, they learn more advanced techniques as you've shown here.

    The pattern you are using, and delegates/unity actions themselves are an "intermediate" subject in our evalution, so when making a beginner tutorial we have avoided using them. As with delegates/actions, we also avoid using concepts like interfaces, inheritance, etc., as well.

    Now, this can be frustrating to the experienced coder who comes to our beginner tutorials wanting to learn Unity, not how to code, but sadly, we have to choose just one audience to target the tutorial projects to, and as you've shown here, we assume an experienced coder and see around our simple structure and make one that is more flexible as they are building the project.

    I trust that it was still helpful to you in learning how Unity approaches a project within the editor, if not the code!
     
    RajRajRaj likes this.
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @bstout : The feedback between on the remote will be slower than on the device or in the editor. It's primarily designed for a control scheme.

    Does the game behave better in the editor, ignoring what's on the remote screen?
    Does the game behave better when built and deployed on to the device directly?

    I'd first try deploying it to your android device and see how it works there.
     
    Seif likes this.
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thanks for everyone's patience, epsecially @OboShape as I've been on holidays. I'm back now!

    And Oboshape, thanks a million for answering people's questions!
     
    IanSmellis and OboShape like this.
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    No bother, Glad to chip in where I can :)
     
    IanSmellis likes this.
  10. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @Kuroskira Are you still having issues with this? If you are, can you repost with the current state of your project and what you need help with?

    My apologies, but I've been on holidays for August and the beginning of September.
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @cotherman The angular velocity (Rigidbody.angularVelocity) is set with the line you have above, and (iirc) the linear velocity (Rigidbody.velocity) is set in the "mover" script.

    Does this help? If not, let me know.
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thank you for the feedback! It really helps to know that people appreciate the experience!
     
  13. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @A_Sloane Thanks for taking the time to help out! We really appreciate it.
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please learn to use code tag properly?

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
    IanSmellis likes this.
  15. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Have you attached your scripts to the appropriate GameObjects?
    Have you populated/set the appropriate public variables in the inspector?
    If you updated a prefab in the scene, have you saved these changes from the instance to the object?
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Hard for me to understand, still, but I'll try to answer as best as possible...

    At this point we will not recreate Space Shooter for Unity 5, but will continue to support it with upgrade guides, etc.

    • Unity 5: When using the mesh collider and adding the simplified mesh, the mesh collider must be "convex" when using Unity 5. Please check "convex" on the mesh collider component.
     
  17. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    When working correctly - for example, with all of the tags created and called correctly - this should destroy all items that leave the Boundary object. This GameObject and its collider should persist throughout the entire game. As there are no renderers on the final object, you should never see this in the game. It simply defines a box that surrounds the game.
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @qqoopp0 When we instantiate our hazards, we can get a reference to the object we have instantiated.

    http://docs.unity3d.com/ScriptReference/Object.Instantiate.html

    Look at the "returned" information from Instantiate. We can get a reference to the object we have instantiated.

    In the example code:
    Code (csharp):
    1.  
    2. Rigidbody clone;
    3. clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
    4. clone.velocity = transform.TransformDirection(Vector3.forward * 10);
    5.  
    ... we create a variable to hold the reference ("clone") and then we get the reference by using "clone =". With this reference we then set the clone's rigidbody velocity directly. In our case, I'd suggest trying to get a reference to the mover script on the hazard, and setting the speed value on the script when we instantiate the hazard.

    Let us know if you have more issues.
     
  19. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @Nuse are you still having issues with this? If you are, please post your current state and where you need help.
     
  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    (^_^)!

    I'll add a note to the OP re: this - and perhaps to the final episode, as this does seem to be a common question.

    Perhaps I'll do a live session on it as well, so we can point people to it...
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @PANDEMICBANDIT

    Can you please learn to use code tag properly?

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @RajRajRaj @OboShape There was (is?) a bug between the "new" UI Tools and the Unity Remote, which only processes one touch (eg: it only simulates a mouse click and drag), so for this to work correctly, you will need to test mobile controls by building and deploying to the mobile device.

    I'll look into the status of the bug "soon", but as I'm still chewing thru a month of messages, it may not be *that* "soon".
     
    RajRajRaj likes this.
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I assume you are following the live training session on converting Space Shooter to Mobile?
    http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/space-shooter-to-mobile

    This should work on Android, but it needs to be deployed.

    If you are using a different control method (eg: a custom thumbstick, etc.) then I am not sure I can help unless we see detailed information.
     
  24. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    Problem Solved U r right Adam that was a bug when i deployed to My Device both UI Images Works Fine...

    But got Another Problem game that i build is going out of the my device screen is there any hack that game works on any resolation or screen size without cutting off or any visul mistakes?
     
  25. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    The resolution for the screen in the base tutorial is different from your device. You will need to adjust this to your device. This is primarily changing the x and z Min/Max settings and perhaps the boundary settings. I can't give you any magic numbers, as I don't know the devices you are targeting.

    There are some "clever" ways to set things based on the viewport of the main camera, but you'll have to experiment with those for yourself for now, as I'm catching up on over a month's work.

    If you're still stuck in a week or so, you can ping me, and I'll try to help you out. The main "trick" to this is to look at the corners of the view port in world space. Viewport (see the docs) is (0,0) in the lower left (iirc) and (1,1) in the upper right... so you can convert that into world space units and start setting borders and things from there.

    Now, iirc, we used a similar technique in the "Hat Trick" catch game (2d) in live training, so you can look there for hints.
     
  26. pixeldude246

    pixeldude246

    Joined:
    Sep 8, 2015
    Posts:
    2
    I really enjoyed doing the Space Shooter tutorial. It was well made, thoughtfully put together and clearly presented. I noticed there are more assets in the project - my guess is for some more advanced tasks. Are there any tutorials that go with those additional assets?
     
  27. StormShadow45

    StormShadow45

    Joined:
    Aug 22, 2015
    Posts:
    3
    Thanks for the help it works now :):):)
     
    IanSmellis likes this.
  28. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Currently there are no tutorials to go with these assets. They are "stretch goals" for the student to explore. To help this, the "done" folder contains a finished scene with additional asteroids and enemy ships implemented.
     
  29. pixeldude246

    pixeldude246

    Joined:
    Sep 8, 2015
    Posts:
    2
    Understood. Thanks, Adam. I will reverse-engineer the "Done" scene. Thanks again for such a useful tutorial.
     
  30. qndat

    qndat

    Joined:
    Sep 9, 2015
    Posts:
    2
    I got many errors in this project, and confused very much, if you guys could help me? when finished the moving ship code : Assets/script/PlayerController.cs(12,17): error CS0619: `UnityEngine.Component.rigidbody' is obsolete: `Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)'

    and Assets/script/PlayerController.cs(12,27): error CS1061: Type `UnityEngine.Component' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

    well I am not familiar with any script and code it really hard >_<
     
  31. Jean_Paul

    Jean_Paul

    Joined:
    Sep 9, 2015
    Posts:
    7
    Awesome tutorial, worked flawlessly... in the editor. After I've built it for web, tried playing it in IE, Edge and Firefox, but the game crashes. So I tried building it for desktop. I hit Play, the "Made with Unity" screen shows up and after it the game crashes as well.
    I don't know what's wrong, I tried the Roll-a-ball tutorial and it worked fine. Any suggestions as to what might be happening would be appreciated.

    I'm using Unity 5.0.0f4 Personal

    Thanks in advance!
     
  32. Jean_Paul

    Jean_Paul

    Joined:
    Sep 9, 2015
    Posts:
    7
    I assume you're using a newer version of Unity, I had the same issue the first time I tried.
    Do the following. Wherever you see rigidbody, switch that with GetComponent<Rigidbody>().

    When you get to the audio part, switch audio to GetComponent<AudioSource>().

    That's the quickest way, ideally you would want a variable to hold a reference for the rigidbody, but that should get you working at least.

    I hope that helps.
     
    IanSmellis likes this.
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please Turn on annotations when watching these videos and follow the upgrade guide in the first post of this thread.
     
  34. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Do you have any data on this? Crash logs? This seems strange...
     
  35. winxalex

    winxalex

    Joined:
    Jun 29, 2014
    Posts:
    166

    I understood the Unity business politic well (attracting more people = more money), but thx for admitting, but still as professional I wouldn't allow myself even on the beginner level (btw I found only few intermediate tutorials overall, and where are advance and can't imagine master classes they are top secret souce of Game studios that give you faraway smeal :D ) to damage people(Why I said damage cos once you learn bad way it is extremely difficult to reverse and here I doesn't count time=money when the game get more complex after 2 years you have enter with your drag and drop tactics :)) I saw you made EventManager tutorials so seem wind of fortune might blow at last. :D
     
    Adam-Buckner likes this.
  36. Jean_Paul

    Jean_Paul

    Joined:
    Sep 9, 2015
    Posts:
    7
    I do for desktop, I'm not sure if it's possible to get one for a web build. Also, I have no idea how to decipher dump files, so thanks. :)

    As an added detail, I'm on Windows 10, I don't know if that would make a difference though, given that the previous tutorial and, as I've just tested today, the Survival Shooter built and ran just fine as a Desktop game.
     

    Attached Files:

  37. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening @Jean_Paul, thought id pop my 2p worth in :)
    See your using the Personal Edition, might be worth updating version.

    looking through the output log, one thing caught my eye.
    output_log.txt
    just out of curiosity, have you tried to run the built EXE with administrator privileges? just being nosey and looking at the exception thrown in the dump file as being possible access rights.
     
  38. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    It's a very difficult tack to sail, as it were. We don't require that our user be trained coders. We don't want to hang a sign on the door saying "Coders Only! No n00bs allowed!". This means that we must always have a thought towards the people who are not the trained coder when we are creating our learning material. At the same time, as much as we try to include as much coding as possible, and try to teach more advanced coding techniques as we teach Unity, we don't want to slam new users with a learning curve that's too steep either. An with that in mind, we trust our experienced coders to see through this, and work with Unity as best as they can.

    I understand that teaching best practices from the very beginning is the best way to teach people who are committed to learning and understanding any subject, and coding especially. We don't have that luxury. Many of our users are young, or just curious, or hobbiest, or artists. Not that we need to coax these shy and reluctant creatures out of thier hiding places and show them that Unity is not as scary as it seems, but we do want to make that first step as easy as possible. Again, we trust our experienced coders to rocket past this, like an Olympian skiing past the bunny slope on their way to the bar after a good day on the slope.

    From my experience of teaching and teaching Unity with this style of lesson, we've been able to grab and bootstrap thousands of people who would never have thought they could make a game. Moreover, as they grow and learn, they realize they need better coding skills and learn the better practices themselves - as they need these skills to make more complex games. As we create more material, we will try to provide as much more advanced material as we can. So far, our team includes 2 people.

    There is also the hard reality of shipping over code elegance. I come from a background of meeting my deadline and deal memo, no matter what. If our students can ship a game that's tightly coupled, but it works, it's on the app store and it sells... yay! Win. No one looks under the hood except the developer. They'll do better next time and realize thier first game was absolute crap when it comes to code - but it worked. It's a learning process. I'd rather have people make games as they learn, than learn first before making a game they may never start.

    All that being said, I feel your post was great... and it makes me wonder how best to make sure people out there get that information... I'll mull it over. As it stands, we can't really host it, due to the synth voice... but the content is ace.
     
    winxalex likes this.
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Good catch, @OboShape! I'd second the thought about getting up to date with 5.2, which just came out.
     
  40. Jean_Paul

    Jean_Paul

    Joined:
    Sep 9, 2015
    Posts:
    7
    Yes, I'm downloading 5.2 right this moment, but slow connection, so it's taking a while.

    As for running with admin privileges, yes, i tried that now and the same thing happened. And exclusively with this tutorial so far.

    Anyway, once 5.2 is up and running, I'll try that, thanks for replying.

    EDIT: I just found these lines on the logs:

    Shader 'Legacy Shaders/Reflective/Bumped Specular': fallback shader 'Legacy Shaders/Reflective/Bumped Diffuse' not found
    Crash!!!


    It couldn't find both shaders? I don't know, I'll have to wait for the download now anyway.
     
    Last edited: Sep 9, 2015
  41. icepick498

    icepick498

    Joined:
    Sep 10, 2015
    Posts:
    1
    Make sure the Rigidbody on your ship has "Is Kinematic" unchecked. That was the problem I had.
     
  42. mehransahto

    mehransahto

    Joined:
    Aug 27, 2015
    Posts:
    5
    I have built the game as shown in the tutorial, but my space ship is not destroying. can any one help me?
     
  43. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can we get more information? At what stage in the tutorial are you? Which lesson? If you've reached the end, at what point did the ship fail to destroy? (And is this the ship itself not being destroyed when hit? Or the bolts fired from the ship not destroying thing they hit? - language issue, sorry!)

    This could be many things, depending on how this is failing. Check spelling and capitalisation: For example if you have ontriggerenter, or OnTriggerenter, not OnTriggerEnter, the function call from the collision will fail.
     
  44. steambucky

    steambucky

    Joined:
    Sep 15, 2013
    Posts:
    33
    I barely have grasp on code at all. I understand that the above code is the solution to my problem, but I have no idea how to implement it. This is my attempt, which of course does not work. Any help welcome.

    usingUnityEngine;
    usingSystem.Collections;

    publicclassNewBehaviourScript : MonoBehaviour
    {

    voidStart ()
    {
    rb = GetComponent<Rigidbody> ();
    }


    voidFixedUpdate ()
    {
    floatmoveHorizontal = Input.GetAxis ("Horizontal");
    floatmoveVertical = Input.GetAxis ("Vertical");

    Vector3movement = newVector3 (moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement;
    }


    }
     
  45. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon @steambucky ,

    I take it you are working through the 'Moving the Player' video?

    almost there with what you have tho, so nice one ;)
    You need to declare a variable at the top to hold your Rigidbody (rb) reference, all variables need a declaration to state their name and what type of information they will hold, then as you have in the Start function, you can assign a value to it.

    depending how far along the vid you are, you will need to add the speed variable and use it when moving your player around. but if you're only half way throo the vid, this comes later :)


    ive edited your code and popped some comments in too.
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.     // need to declare a speed multiplier variable to use, otherwise your ship will be super slow
    8.     // (just remember to change it in the inspector! ;))
    9.     public float speed;
    10.     // need to declare this variable to hold our reference to the rigidbody so we can use it througout the script
    11.     Rigidbody rb;
    12.  
    13.  
    14.     void Start ()
    15.     {
    16.         // if you didnt create the declaration of rb above, it wouldnt know what you are trying to assign to.
    17.         rb = GetComponent<Rigidbody> ();
    18.     }
    19.  
    20.  
    21.     void FixedUpdate ()
    22.     {
    23.         float moveHorizontal = Input.GetAxis ("Horizontal");
    24.         float moveVertical = Input.GetAxis ("Vertical");
    25.      
    26.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    27.         rb.velocity = movement * speed;
    28.     }
    29. }
    30.  
    hopefully that makes sense and helps a bit..
     
    Last edited: Sep 10, 2015
    IanSmellis and steambucky like this.
  46. steambucky

    steambucky

    Joined:
    Sep 15, 2013
    Posts:
    33
    That was VERY helpful of you :) thanks very much. Thats help me understand. I had to change:

    public class NewBehaviourScript : MonoBehaviour

    to

    public class PlayerController : MonoBehaviour

    So now it complies without errors but still the ship doesn't move. I have altered the speed. The script is on the player, no errors...any ideas?

    EDIT - FIXED - I accidentally removed the rigid body which stop the entire thing working.
     
    Last edited: Sep 10, 2015
    OboShape and IanSmellis like this.
  47. Jean_Paul

    Jean_Paul

    Joined:
    Sep 9, 2015
    Posts:
    7

    Updating to Unity 5.2 and rebuilding worked great, both for web and standalone Windows. Thank you both, @Adam Buckner and @OboShape for the attention and tip.
     
    Adam-Buckner and OboShape like this.
  48. BoeTaito

    BoeTaito

    Joined:
    Aug 11, 2015
    Posts:
    4
    Hi guys, I've got up to part 14 - Counting Points and I've hit a snag. For one reason or another, I can't drag any form of text into the GameController to display the score. I think I'd be able to make a workaround to fix this, but I'm pretty sure It's just something small that I've missed. Do you guys mind checking the code to see if this is the case?

    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.     private int Score;
    15.  
    16.     void Start ()
    17.     {
    18.         Score = 0;
    19.         UpdateScore ();
    20.         StartCoroutine (SpawnWaves());
    21.     }
    22.    
    23.     IEnumerator SpawnWaves ()
    24.     {
    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.     void UpdateScore ()
    46.     {
    47.         ScoreText.text = "Score: " + Score;
    48.     }
    49. }

    Thanks,

    -EvilBarrels
     
  49. mehransahto

    mehransahto

    Joined:
    Aug 27, 2015
    Posts:
    5
    I have Check spelling and capitalisation.Every thing is ok. i have completed all of the game tutorials.Bolts are working correctly.Ship itself not being destroyed when hit the hazards and hazards are also not being destroyed when they hit the ship. I have use c# language
     
  50. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning @EvilBarrels,

    where you have
    Code (CSharp):
    1. public GUIText ScoreText;
    this will expose the ScoreText variable slot in the Inspector, and you will only be able to drag in an object of type 'GUIText'.
    you can double check in the scene heirarchy to ensure that your 'Score Text' object, is of type 'GUI Text'. (highlight it and check the inspector)

    or did you add your 'Score Text' to the scene by using UI > Text? this is using the Unity 4.6 and later UI system and is of the type 'Text'.
    One way to tell, using the GUIText, you will not have a canvas in the scene heirarchy and using the UI you will.

    To get the GUIText going, if you can switch on Captions/Annotations in the video there are comments to create GUIText component. (@20 seconds)


    if its the UI and the canvas your using instead, give a shout, and we can help with that.