Search Unity

Space Shooter Tutorial Q&A

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

  1. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    I'm as stumped as you probably are...
    Can you post the Enemy Ship game object itself?
    I notice the layer for the vehicle_enemyShip child is blank, can you set it to Default
    Also, make sure there is no "private" in your mover script:
    Code (csharp):
    1.  
    2. public class Mover : MonoBehaviour {
    3.  
    4.     public Rigidbody rb;
    5.     public float speed;
    6.  
    7.     void Start()
    8.     {
    9.         rb = GetComponent<Rigidbody>();
    10.         rb.velocity = transform.forward * speed;
    11.     }
    12.  

    At this point I would bring the EnemyShip prefab back in the the main project and delete it from the prefabs.
    Then, reset the transform on it, then save and exit Unity.
    Then restart Unity, reset transform on the EnemyShip back to
    upload_2017-8-17_18-59-46.png
    and then move it back to the prefabs.

    After that, we're heading into incantations, grass skirts and animal sacrifice.
     
    Last edited: Aug 18, 2017
    Connarhea likes this.
  2. Samsood27

    Samsood27

    Joined:
    Aug 18, 2017
    Posts:
    1


    I have used the same code but still cannot make the shots fired i have even changed the U
     
  3. Paliandro

    Paliandro

    Joined:
    Aug 9, 2017
    Posts:
    20
    So, working on the part of enabling rapid firing, I ran into a problem again, and once again I can't seem to find a way to fix this. I hope someone can help.
    I didn't cap it, but the red line under FixedUpdate tells me that
    "Feature 'Local Functions' is not available in C#4. Please use language version 7 or greater. The variable 'FixedUpdate' is declared but never used"

    Once again I think my code looks pretty much like in the tutorial.
     

    Attached Files:

  4. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    At line 34 of PlayerController you need an additional closing curly brace "}" to close out the Update method
     
  5. Marriaud

    Marriaud

    Joined:
    Aug 19, 2017
    Posts:
    1
    Hi everybody,

    I've a question about the boundaries : it works, but if I keep pressing the up arrow for example, my ship can go over the limit, i.e. 12.2 on the Z axis, boundary set to 12. I can reproduce that on any boundary. Each time the ship can go 0.2 over the limit. When I release the key, the ship goes back slowly into the boundaries. Why is that? We set the position in FixedUpdate and this position is still modified after that, why?

    IBy modifying the speed property of the player ship, I can see that it can go 0.01*speed over the limit. The greater the speed, the further the ship can go over the boundaries.
     
    Last edited: Aug 19, 2017
  6. jekkst

    jekkst

    Joined:
    Aug 17, 2017
    Posts:
    2
    Hey guys, new to Unity and was using the Space Shooter Tut. I'm at the "Extending.." part, and until now, everything went well - now I have a problem with the Enemy Engine tho. (When at standard settings as downloaded) it "blows" towards.. maybe 70°? I couldn't find a rotation that made it go upwards entirely, some made it go to the top mostly but with some weird angles sometimes. I didn't see the tutor making any changes to the engines_enemy, so I would love help here. I hope you guys understand what I mean, can't describe it better with my current english skills.
     
    Hammeric likes this.
  7. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    I just got to the same step you're at and hit the same problem. I was able to fix it to match the tutorial video by rotating the child object by -90 in Y to make the particles leave in the proper direction, and then going into "Force over Lifetime" inside of Particle System and changing Z from 2 to 0.

    Hope that helps. :)
     
    Burgers_and_Frys, Hammeric and jekkst like this.
  8. jekkst

    jekkst

    Joined:
    Aug 17, 2017
    Posts:
    2
    That helped and I got some more things I can "play around with" now that I seem to know what it does. Thousand thanks!
    Edit: Typo
     
  9. Connarhea

    Connarhea

    Joined:
    Mar 29, 2015
    Posts:
    19
    Again thank you for all the help. Sadly, this didn't work. What did happen though, was when I put the enemy ship into the main project and pressed play, the ship that was already there moved down the screen and evaded as it should but every ship after that (all the ships that were instances) spawned as they have been doing and didn't move onto the game screen.

    I'll drop my GameController script in to see if it's something to do with this as that's the only other thing that could change the ships movement upon spawn right?

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class GameController : MonoBehaviour {
    6.                    
    7.     public GameObject[] hazards;
    8.     public Vector3 spawnValues;
    9.     public int hazardCount;
    10.     public float spawnWait;
    11.     public float startWait;
    12.     public float waveWait;
    13.  
    14.     public GUIText scoreText, restartText, GameOverText;
    15.  
    16.     private bool gameOver, restart;
    17.     private int score;
    18.                  
    19.     void Start()
    20.     {
    21.         gameOver = false;
    22.         restart = false;
    23.         restartText.text = "";
    24.         GameOverText.text = "";
    25.         score = 0;
    26.         UpdateScore();
    27.         StartCoroutine (SpawnWaves ());
    28.     }
    29.  
    30.     void Update()
    31.     {
    32.         if (restart)
    33.         {
    34.             if (Input.GetKeyDown(KeyCode.R))
    35.             {
    36.                 SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    37.             }
    38.         }    
    39.     }
    40.  
    41.     IEnumerator SpawnWaves ()
    42.     {
    43.         yield return new WaitForSeconds(startWait);
    44.         while (true)
    45.         {                                    
    46.             for (int i = 0; i < hazardCount; i++)
    47.             {                                
    48.                 GameObject hazard = hazards[Random.Range (0, hazards.Length)];
    49.                 Vector3 spawnPosition = new Vector3 (Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    50.                 Quaternion spawnRotation = Quaternion.identity;
    51.                 Instantiate (hazard, spawnPosition, spawnRotation);
    52.                 yield return new WaitForSeconds(spawnWait);
    53.             }
    54.             yield return new WaitForSeconds (waveWait);
    55.             hazardCount += 1;
    56.  
    57.             if (gameOver)
    58.             {
    59.                 restartText.text = "Press 'R' for Restart";
    60.                 restart = true;
    61.                 break;
    62.             }
    63.         }
    64.     }
    65.    
    66.     public void Addscore (int newScorevalue)
    67.     {
    68.         score += newScorevalue;
    69.         UpdateScore();
    70.     }  
    71.  
    72.     void UpdateScore()
    73.     {
    74.         scoreText.text = "Score: " + score;
    75.     }
    76.  
    77.     public void GameOver()
    78.     {
    79.         GameOverText.text = "Game Over!";
    80.         gameOver = true;
    81.     }
    82. }
     
  10. panoskal

    panoskal

    Joined:
    Mar 31, 2017
    Posts:
    28
    @Connarhea
    Here is what I want you to do.
    Edit the EnemyShip prefab so that the Mover script component is above the EvasiveManeuver script component.
     
    gwnguy likes this.
  11. Connarhea

    Connarhea

    Joined:
    Mar 29, 2015
    Posts:
    19
    I could kiss you, this has fixed it. Why would this happen though. I rearranged my scripts to be alphabetical because I didn't realise it would cause an issue
    @gwnguy
     
  12. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Congrats @Conn!

    And @panoskal, how did you know of this. I don't recall ever seeing sn order dependency in scripts in game objects. This solution is brilliant! I too thank you. Of course, now the animal sacrifices are off........

    update:
    https://docs.unity3d.com/Manual/class-ScriptExecution.html
    Well, I'll be danged. Still, would *NEVER* have even thought to look with @panoskal
     
  13. panoskal

    panoskal

    Joined:
    Mar 31, 2017
    Posts:
    28
    @Connarhea, @gwnguy
    I won't pretend to really know how it works, but here is the logic I used.

    Assuming the scripts run in order,

    the Mover script changes the velocity of the rigidbody to transform.forward * speed on Start ().
    Then the EvasiveManeuver script assigns the value of the rigidbody's z velocity to a variable called currentSpeed,
    on Start () as well, and uses that variable to change the velocity again on FixedUpdate () on the line that reads
    rb.velocity = new Vector3 (newManeuver, 0.0f, currentSpeed);

    If the EvasiveManeuver's Start() runs first the currentSpeed variable is going to come up as 0, since the Mover script didn't get to change the rigidbody's z velocity yet.
     
  14. Connarhea

    Connarhea

    Joined:
    Mar 29, 2015
    Posts:
    19
    You're absolutely right. Would work in the old order if I used Void Awake () in the Mover script as that would call first (from what I've been reading) I know for certain that I've read about other ways within Unity to order script preference (maybe the wrong word, run order?) but I can't for the life of me remember it.

    @gwnguy I was so into wearing the grass skirts too :'(
     
  15. Connarhea

    Connarhea

    Joined:
    Mar 29, 2015
    Posts:
    19
    Another (hopefully easy to answer question) that I think got asked earlier in the thread but I never found the response.

    Why does the restart text and the ability to actually restart the game only happen after everything has left the screen? If I follow the code it seems like as soon as the player object is destroyed and its explosion gets instantiated the gamOver bool gets set to true and that should cause the restart process straight away.

    I've added a small piece of code into my game to increase hazard count every wave, so if someone gets a fair few waves in and dies early on in that wave it could cause a big issue with them having to wait for 20+ enemies to go through the play area.
     
  16. Connarhea

    Connarhea

    Joined:
    Mar 29, 2015
    Posts:
    19
    Sorry, not meaning to spam but along with the above question I have one more thing to ask. If you are building this game as a pc standalone, how can you go about making sure the game loads the GUI stuff correctly. Can you keep them within the bounds of the background through code?

    Also is there a way of limiting the size of the window that the game opens in? Whenever i open the game there are the obvious black borders on either side due to the game being portrait not landscape, but I've also noticed that the explosions go out over the background and display on top of the black borders too.
     
  17. panoskal

    panoskal

    Joined:
    Mar 31, 2017
    Posts:
    28
    @Connarhea
    For your first question, you are going to want to look to the GameController script.
    Specifically on this part of it.
    Code (CSharp):
    1. IEnumerator SpawnWaves ()
    2.     {
    3.         yield return new WaitForSeconds (startWait);
    4.         while (true)
    5.         {
    6.             for (int i = 0; i < hazardCount; i++)
    7.             {
    8.                 GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    9.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    10.                 Quaternion spawnRotation = Quaternion.identity;
    11.                 Instantiate (hazard, spawnPosition, spawnRotation);
    12.                 yield return new WaitForSeconds (spawnWait);
    13.             }
    14.             yield return new WaitForSeconds (waveWait);
    15.          
    16.             if (gameOver)
    17.             {
    18.                 restartText.text = "Press 'R' for Restart";
    19.                 restart = true;
    20.                 break;
    21.             }
    22.         }
    23.     }
    This is called on Start () through this:
    StartCoroutine (SpawnWaves ());

    If you follow it closely, this is what it does:

    It waits for as many second as you have put on the startWait variable.
    Then it starts instantiating as many hazards as you have put on the hazardCount variable, waiting (spawnWait) seconds between each instantiation (if that's a word).
    Then it waits for (waveWait) seconds and THEN checks if the gameOver bool is true.
    If it is, the restart bool becomes true and through break; the while (true) loop stops, otherwise it won't stop and it will just keep going.

    If you want to be able to restart instantly, I suggest you write this code at the start of the Update(), on the GameController script:

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

    Note that there is no break; here. When I was copying pasting I was always forgetting to delete it and was getting compiler errors.

    Now you are not going to need the same on SpawnWaves but you should still keep the:

    if (gameOver)
    {
    break;
    }

    so the while loop stops. Otherwise waves will never stop spawning if you don't press "R".
     
  18. LoLo2207

    LoLo2207

    Joined:
    Mar 22, 2014
    Posts:
    4
    Hi, i've completed this tutorial, and the only problem I have is that I can't see the explosions' vfx. The object instantiates correctly, the sound is played, and the bolt/asteroid/player ship objects are destroyed correctly, but the particle vfx is never shown.

    Maybe the vfx is corrupt or needs some changes to work with the latest release?
     

    Attached Files:

  19. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    I ran through the tutorial with the latest install version and the particles seem to be displaying just fine for me.

    I assume that they're instantiating correctly in the Hierarchy when you hear the sound. Can you pause the game immediately when the sound triggers, then see if it's perhaps spawning in a weird location in your scene view?

    Edit: also, maybe try loading up the _Complete-Game scene inside the /_Complete-Game folder in the Project Panel and see if they work in that example?
     
    Last edited: Aug 21, 2017
  20. LoLo2207

    LoLo2207

    Joined:
    Mar 22, 2014
    Posts:
    4
    PS: already tried to open the _Complete-Game scene, even tried to copy the done_explosion_asteroid prefab to my Main Scene but the vfx won't show up either.

    PS2: also getting these Quaternion errors, like these guys https://feedback.unity3d.com/sugges...t-0f-0-dot-0f-rb-dot-velocity-dot-x-star-tilt but it doesn't affect gameplay. Seems to be a float precision issue.

    explosion_asteroid.png explosion_player.png
     
    Last edited: Aug 21, 2017
  21. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    I haven't seen any Quaternion errors like the guy you mentioned... not sure I'd even know where to start to track that down without digging through the entire project.

    If you rollout your Particle Systems section under your explosion_asteroid, is Play on Awake checked? I'm trying whatever I can think of to replicate your problem...

    If you feel like it, zip up your project folder and I can see if your error can be replicated on my install... that'll at least let you know if it was some obscure error or not.
     
  22. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Hi there,
    I just started Unity now doing the shooter tutorial managed to follow with the updates and so on, but now i got an issue with the bolt animation is very slow increasing speed will make it jump by speed amount. in previous tutorial rolling a ball it was mentioned that slow animation/movement is related to Gameobject scale so i reduced the scale and as expected the bolt became a dot :p
    Thanks for any advise regarding this matter.
     
  23. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    Can you post a screenshot of your Inspector settings for your Shot prefab?
     
  24. LoLo2207

    LoLo2207

    Joined:
    Mar 22, 2014
    Posts:
    4
    There you have it:

    http://www51.zippyshare.com/v/DCXoRzsc/file.html

    Also, the 3 play on awake are enabled.
    particle_awake.png

    Don't bang your head too much with this, it's just a small issue.

    Thanks anyways.
     
  25. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    I was able to use your project and the particles showed up just fine...
    upload_2017-8-22_12-28-59.png

    I was hoping to see it broken and maybe track down something fixable. With it working right out of the box for me... I don't know. This definitely seems to be a problem beyond just this project... maybe try the Editor & General Support forum to track this one down... https://forum.unity3d.com/forums/editor-general-support.10/

    I'm curious to know if they can find out what's going on.
     
  26. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    here it is but please note that's now I using a workaround see my Mover script looks like this
    with speed=115 and accelerationSpeed=1400 I get somewhat decent movement but still jumpy not as smooth as in the tutorial video:(

    public class Mover : MonoBehaviour
    {
    private Rigidbody rb;
    public float speed;
    public float accelerationSpeed; A
    void Start()
    {
    rb = GetComponent<Rigidbody>();
    rb.velocity = transform.forward * speed;
    }

    private void FixedUpdate()
    {
    rb.velocity = Vector3.MoveTowards(rb.velocity,
    transform.forward * speed,
    Time.deltaTime * accelerationSpeed);
    }

    }
     
  27. panoskal

    panoskal

    Joined:
    Mar 31, 2017
    Posts:
    28
    @Keita-kun
    Is the Player gameobject's rotation 0,0,0 on the inspector,
    as well as its child's, Shot Spawn?
     
  28. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    I am still at shot/bolt creation and script movement is ugly/slow didn't complete the shooting part yet see image above.
     
  29. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    I am happy camper after reviewing all part of project and so on I found an extra Rigidbody on the vfx child of Bolt GameObject stuck there may be after a crash I experienced while playing params to solve my problem.
    Indeed everything's fine now smooth movement and the part for shooting works as expected but I kept the workaround for
    movement dow I am lazy:p
     
  30. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    I've been playing with your workaround and from what I can see so far, it doesn't really appear to do much for me.

    I'm trying to make sure I 100% understand the Rigidbody.velocity and Vector3.MoveTowards functions, and they don't seem exactly interchangable like you're using them. As I understand them now (and maybe someone could correct me), but it seems like Rigidbody.velocity is a Vector3 that applies its 3 values to modify the position of the Rigidbody's position, and Vector3.MoveToward's 3 values are startLocation, endLocation, and maxDistance.

    I was playing with the values and changing Acceleration Speed in the Inspector didn't change the behavior at all.

    After reading through the Scripting API reference, I'd remove rb.velocity assignment from FixedUpdate().
    From Rigidbody.velocity reference:
    I'm glad you found that extra Rigidbody... I was running out of ideas for things to look for...
     
  31. Connarhea

    Connarhea

    Joined:
    Mar 29, 2015
    Posts:
    19
    Yeah I managed to figure this one out after about half an hour of hacking up the code and swapping it around :D is there a way of programmatically (now is that one a word?) getting the restartText to either fade in for over a couple of second or even just wait a small amount of time after the Game Over text to show.

    Also do you have any idea on how to lock the GUI parts if the game is made as a PC standalone? Or how to lock the size of the game window when it's launched so this doesn't have to be done?
     
  32. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Yeah because of the crash when I started Unity again the project seemed fine just loaded the scene and missed this one I was playing with params to solve my issue.

    Why i am using the Vector3.MoveTowards instead of Rigidbody.velocity I got the idea while looking for any help for script movement issue I found this in the answers it explains how to make a gradual movement to reach top speed.
    instead of a sudden increase of velocity value also in API manual they recommend to avoid that practice : Don't set the velocity of an object every physics step, this will lead to unrealistic physics simulation.
    That's all i can say, don't forget I am new born:) here so an expert may have a better explanation then me dow
     
  33. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    I'm still toying with an easy solution for the text fading, but I already had this inside of Start() in my PlayerController.cs:
    Code (CSharp):
    1. Screen.SetResolution (600, 900, false);
    (width, height, fullscreen)
     
  34. LoLo2207

    LoLo2207

    Joined:
    Mar 22, 2014
    Posts:
    4
    Nevermind, removed both Unity & Nvidia drivers, and then reinstalled the newest drivers & the stable unity version (i had the security patch one). Now it works. YAY!
     
    Wykk likes this.
  35. DonaldUnity

    DonaldUnity

    Joined:
    Aug 23, 2017
    Posts:
    1
    Why don´t I have the platform Web player? I only got Linux, windows, ios, android, facebook etc.
    Do you know how to get the platform Web Player to space shooter?
     
  36. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    WebGL is the new webplayer.
     
  37. cccons

    cccons

    Joined:
    Aug 25, 2017
    Posts:
    1
    I have been having the same issue. While I'm not sure if this actually fixes anything, I noticed that inside the "Emission" dropdown for "explosion_asteroid", the "Bursts" property was set at 0. I changed it to 10 (which is arbitrary) but actually saw some particles. This might work for you.

    Also, this might help suggest if something is broken in the Assets download.

    P.S. I'd love feedback about whether I'm on the right track with this.
     

    Attached Files:

    jimmack likes this.
  38. Wykk

    Wykk

    Joined:
    Jan 18, 2013
    Posts:
    9
    You might be onto something, but I'm not sure why yours was set at 0. In my version (2017.1.0f3), under Emission/Bursts I have 5 fields (Time, Min, Max, Cycles, Interval). Both Min and Max are set to 50 in this prefab, so maybe increase your 10 up to 50 and you might see the same results?

    Also, what version are you running that has "Count" instead of "Min" and "Max"?
     
  39. Kinhary

    Kinhary

    Joined:
    Aug 28, 2017
    Posts:
    1
    Hey, I'm currently trying to do the audio part of the space shooter tutorial on Unity 5.6.1f1 the only thing that isn't working for me is the Player Explosion sound. Ive tried doing what the tutorial video says but that just adds "explosion_player (1)" into my hierarchy. I've even tried going into the explosion_player prefab and clicking on Add Component > Audio > Audio Source and then clicking the circle with a dot in the middle of it for Audio Clip to add that sound in. However I'm still not getting any sound for my ship exploding.
     
  40. OrdinaryBen

    OrdinaryBen

    Joined:
    Aug 29, 2017
    Posts:
    1
    Hello guys, this is my first post.
    I've been following through some tutorials I'm completely new to C# and Unity and fairly new to programming in general.
    I have some HTML and CSS, knowledge, and dabbled with a some C++ and Javascript basics on SoloLearn, but I have the basic grasp on programming and am definitely getting better. This is the first time I've run into an issue I can not solve and really need some help. I'm at the part where I'm making waves and I just got to the part of the tutorial where it adds spawnWait and startWait, video link at correct time HERE.

    The problem is, instead of spawning all separately like in the video, mine STILL spawn all together, all 10 asteroids at once except now, the asteroids go all in crazy directions and sometimes I can't shoot them! It's like they crash into each other then go off course, and above the boundary to where my bullets don't hit!

    Here is the code I have:
    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.  
    14.     void Start()
    15.     {
    16.         StartCoroutine(SpawnWaves());
    17.     }
    18.  
    19.     IEnumerator SpawnWaves()
    20.     {
    21.         yield return new WaitForSeconds(startWait);
    22.         for (int i = 0; i < hazardCount; i++)
    23.         {
    24.             Vector3 spawnPosition = new Vector3 (Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    25.             Quaternion spawnRotation = Quaternion.identity;
    26.             Instantiate(hazard, spawnPosition, spawnRotation);
    27.         }
    28.     }
    29. }
    30.  
    Edit: As soon as I made this I checked out the source code once again and noticed there were TWO instances of the yield return new WaitForSeconds(); and one was missing in mine at the bottom. (The "yield return new WaitForSeconds(spawnWait);")
     
    Last edited: Aug 29, 2017
  41. Halo_Liberation

    Halo_Liberation

    Joined:
    Mar 6, 2017
    Posts:
    26
    This is completely unrelated to the space shooter tutorial but there are a lot of wicked smart people here so I thought I would ask. Is unity able to update graphics to older games? An example being the star wars battlefront 2 game on PS2. If you had access to the codes and scripts could one potentially upgrade the graphics slightly and coding of course and enable it to work on a newer console for practice purposes? I ask because me and a friend got into a debate on whether or not it could be done and this is far above our heads.

    If this is a subject that shouldn't be discussed I will gladly remove this comment. I just don't know where else I can put this and this was the last place I could think of.
     
  42. OneBogdan

    OneBogdan

    Joined:
    Aug 30, 2017
    Posts:
    1
    i don't see what is wrong please help me...(collider doesn't work at all) Note i copy paste the scripts
    using UnityEngine;
    using System.Collections;



    public class DestroyByTime : MonoBehaviour {
    public float lifetime;
    void Start()
    {

    Destroy(gameObject, lifetime);
    }

    }
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using System.Collections;

    public class GameController : MonoBehaviour
    {
    public GameObject hazard;
    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))
    {
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }

    }
    }

    IEnumerator SpawnWaves()
    {
    yield return new WaitForSeconds(startWait);
    while (true)
    {
    for (int i = 0; i < hazardCount; i++)
    {

    Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    Quaternion spawnRotation = Quaternion.identity;
    Instantiate(hazard, spawnPosition, spawnRotation);
    yield return new WaitForSeconds(spawnWait);
    }
    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;

    }
    }
    using UnityEngine;
    using System.Collections;



    public class DestroyByContact : MonoBehaviour
    {
    public GameObject PlayerExplosion;
    public GameObject explosion;
    public int scoreValue;
    private GameController gameController;
    void Start()
    {
    GameObject gameControllerObject = GameObject.FindGameObjectWithTag("GameController");
    if(gameController != null)
    {
    gameController = gameControllerObject.GetComponent<GameController>();
    }
    if (gameController == null)
    {
    Debug.Log("Cannot find 'GameController' script");
    }
    }
    void OnTriggerEnter(Collider other) {
    if (other.tag == "Boundary")
    {
    return;
    }
    if (explosion != null)
    {
    Instantiate(explosion, transform.position, transform.rotation);
    }
    if (other.tag == "Player")
    {
    Instantiate(PlayerExplosion, other.transform.position, other.transform.rotation);
    gameController.GameOver();
    }

    gameController.AddScore(scoreValue);
    Destroy(other.gameObject);
    Destroy(gameObject);
    }
    }
    using UnityEngine;
    using System.Collections;



    public class DestroybyBoundary : MonoBehaviour
    {
    void OnTriggerExit(Collider other)
    {
    Destroy(other.gameObject);
    }
    }
    using UnityEngine;
    using System.Collections;
    [System.Serializable]
    public class Boundary
    {
    public float xMin, xMax, zMin, zMax;
    }

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

    }

    }
    using UnityEngine;
    using System.Collections;



    public class Mover : MonoBehaviour {
    public float speed;
    private void Start()
    {
    GetComponent<Rigidbody>().velocity = transform.forward * speed;
    }
    }
     
  43. TheDreamFox

    TheDreamFox

    Joined:
    Sep 4, 2017
    Posts:
    1
    I have the same issue, i did what you did but the asteroid still doesn't make contact with my bolts.

    This is my current code for the destroy by contact

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class DestroyByContact : MonoBehaviour
    7. {
    8.     void OnTiggerEnter (Collider other)
    9.     {
    10.         if (other.tag == "Boundary")
    11.         {
    12.             return;
    13.         }
    14.         Destroy(other.gameObject);
    15.         Destroy(gameObject);
    16.     }
    17.  
    18.  
    19. }
    20.  
    Edit: My bolts are triggers but the collider on the asteroid is not
     
  44. Toonas

    Toonas

    Joined:
    Sep 4, 2017
    Posts:
    19
    Hello. I have a little problem with restart in tutorial: when i restart my game after game over all light in game is lost.
    p.s. sorry for my English

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6.  
    7. public class GameController : MonoBehaviour {
    8.  
    9.     public GameObject hazard;
    10.     public Vector3 spawnValues;
    11.     public int hazardCount;
    12.  
    13.     public float timeStart;
    14.     public float timeHazard;
    15.     public float timeWave;
    16.  
    17.     public Text textScore;
    18.     public Text textGameOver;
    19.     public Text textRestart;
    20.  
    21.     private int score;
    22.     private bool isGameOver;
    23.     private bool isRestart;
    24.  
    25.     void Start()
    26.     {
    27.         isGameOver = false;
    28.         isRestart = true;
    29.         textGameOver.text = "";
    30.         textRestart.text = "";
    31.         score = 0;
    32.         UpdateScore();
    33.         StartCoroutine(SpawnWaves());
    34.     }
    35.  
    36.     void Update()
    37.     {
    38.         if (isRestart)
    39.         {
    40.             if (Input.GetKeyDown(KeyCode.R))
    41.             {
    42.                 SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
    43.             }
    44.         }
    45.     }
    46.  
    47.     IEnumerator SpawnWaves()
    48.     {
    49.         yield return new WaitForSeconds(timeStart);
    50.         while (true)
    51.         {
    52.             for (int i = 0; i < hazardCount; i++)
    53.             {
    54.                 Instantiate(hazard, new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z), Quaternion.identity);
    55.                 yield return new WaitForSeconds(timeHazard);
    56.             }
    57.             yield return new WaitForSeconds(timeWave);
    58.  
    59.             if (isGameOver)
    60.             {
    61.                 textRestart.text = "Press 'R' to restart!";
    62.                 isRestart = true;
    63.                 break;
    64.             }
    65.         }
    66.     }
    67.  
    68.     public void UpdateScore(int plusScore = 0)
    69.     {
    70.         score += plusScore;
    71.         textScore.text = "Score: " + score;
    72.     }
    73.  
    74.     public void GameOver()
    75.     {
    76.         isGameOver = true;
    77.         textGameOver.text = "Game Over!";
    78.     }
    79. }
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyByContact : MonoBehaviour {
    6.  
    7.     public GameObject explosion;
    8.     public GameObject explosionPlayer;
    9.  
    10.     void OnTriggerEnter(Collider other)
    11.     {
    12.         if (other.tag == "Boundary")
    13.             return;
    14.         Instantiate(explosion, transform.position, transform.rotation);
    15.  
    16.         GameObject Contr = GameObject.FindGameObjectWithTag("GameController");
    17.         if (Contr != null)
    18.         {
    19.             Contr.GetComponent<GameController>().UpdateScore(1);
    20.         }
    21.         else
    22.         {
    23.             Debug.Log("Can't find 'GameController'");
    24.         }
    25.  
    26.         if (other.tag == "Player")
    27.         {
    28.             Instantiate(explosionPlayer, other.transform.position, other.transform.rotation);
    29.             Contr.GetComponent<GameController>().GameOver();
    30.         }
    31.  
    32.         Destroy(other.gameObject);
    33.         Destroy(gameObject);
    34.     }
    35. }
    36.  
     
  45. Xilas_Crowe

    Xilas_Crowe

    Joined:
    Sep 4, 2017
    Posts:
    1
    This is probably a stupid question, but right at the beginning where you set Build Settings to "Web Player," I can't find Web Player, can anyone tell me what I'm doing wrong?
     

    Attached Files:

  46. Elbrecht

    Elbrecht

    Joined:
    Sep 5, 2017
    Posts:
    1
    At the beginning of the tutorial, it says to change the build target to Web Player. I am using version 2017.1.0f3 Personal and I don't have Web Player as on option in my build targets list. Is it no longer supported? Do I need to download something to be able to build for it?
     
  47. Toonas

    Toonas

    Joined:
    Sep 4, 2017
    Posts:
    19
    Hello! Autor of this tutorials use Mac version of Unity (you can see it in every lesson). If you want create Web version of your project just use WebGL.
    P.S. sorry for my English
     
  48. ZekeDaCoder

    ZekeDaCoder

    Joined:
    Jul 18, 2017
    Posts:
    1
    Hello everyone,
    I am somewhat new to Unity, as I just finished the roll-a-ball tutorial and I just recently started the Space Shooter tutorial. I was following along to the first video, and I got to the part where it says to change the build target to 'Web Player'. I understand that the tutorials were made in Unity 4.1, and my current version of Unity is 5. I could not find the 'Web Player' build target, so I used the one that seemed the most similar, which was the 'WebGL' build target. Next, the video said to change the resolution of the game view to 600 by 900. I did that, and I saved the layout and named it 'Space Shooter'. The game view changed to what seemed to me to be 900 by 600, the opposite of what I was expecting. I deleted the layout, and I tried to change it to 900 by 600. I need help getting the right layout and saving it. Thanks!
     
    Last edited: Sep 6, 2017
  49. Hammeric

    Hammeric

    Joined:
    Sep 23, 2015
    Posts:
    1
    So I just finished this tutorial in Unity 2017.1.0f3, and there the tutorial runs fine as long as you read the upgraded guide for Unity 5.
    However there is a small issue with the particle system for the enemy engines.
    upload_2017-9-7_18-12-8.png

    To fix this in the 'engines_enemy' object in the 'Enemy ship' prefab change the Y value on Rotation to 270.
    In the Particle System change the Force over Lifetime values of Z from 2 to 0, and the Y from 0 to 2.
    upload_2017-9-7_18-15-36.png

    you should now have correct engines.

    upload_2017-9-7_18-16-17.png
     
    unity_iUvEAdmUOVbIZw and Natez74 like this.
  50. mc3

    mc3

    Joined:
    Mar 27, 2016
    Posts:
    19

    I got confused a little here:
    I was not sure how the script was to be changed from what is in the tutorial.

    Is the code shown in this example valid for the current version of unity?
    https://unity3d.com/earn/tutorials/projects/space-shooter/moving-the-player?playlist=17147

    Ok. I think I found the solution on page 15 here.
    https://oc.unity3d.com/index.php/s/...182.741654025.1504709514-684529510.1503940255