Search Unity

Space Shooter Tutorial Q&A

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

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @zonder Let us know if you are still having issues! @SicraS has asked some very good questions and made some very valid points!
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @shintaru22 Let me know if you are still having issues. What @SicraS says is correct.

    You can break out of a while loop by either setting a condition in the while statement, or by using the keyword break.
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @SicraS Thanks for all your help and the replies. This is very helpful, and I really appreciate it!
     
    OboShape and SicraS like this.
  4. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    Adam, wow:) frankly speaking I solved my problem already, but I do want to know your way. Thank you very much for such detailed response. I'll try to dig it.
     
  5. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    Adam, I have just tested you health script for enemy and it works. I am amazed by how it simple. There was some problem with score value, the script added score every time when was contact bullet with hazard. I don't know it is right or not decision but these lines solved the problem:
    Code (CSharp):
    1.         if (health <= 0)
    2.         {
    3.             Destroy (gameObject);
    4.             gameController.AddScore (scoreValue);
    5.             Destroy (other.gameObject);
    6.         }
    The only problem is smallExplosion. I am going to use different weapon for player ( different bolt) within level and that is why I need different impact effects for the hits. But it's imposible with this script. At least I can't figure it out. I told you that I implemented health already. I created bullets with damage value script and added standalone health script (with health bar for boss) to hazard. This way is more complicated that yours but I have a proper effect for every hit (this writen in bullet script). I am not a programmer at all so may be there is a way to get this effect with your script. What do you think?

    PS I did not tested player health yet
     
  6. SicraS

    SicraS

    Joined:
    Sep 22, 2015
    Posts:
    7
    It's OK @Adam Buckner ! We are here to ask, learn and help others if our knowledge allows it. I'm recently finished my developement studies, and I'll try to help anyone I can...

    So, thanks for the post-tag and for these resources you put in our hands so we could learn and have fun using / learning Unity! Very much appreciated! :)
     
    Last edited: Oct 8, 2015
    IanSmellis and OboShape like this.
  7. AllTheGoodNamesWereTaken

    AllTheGoodNamesWereTaken

    Joined:
    Sep 24, 2015
    Posts:
    14
    Thank you for the great tutorial.
     
    Adam-Buckner, steambucky and yashtd like this.
  8. whiteskull24

    whiteskull24

    Joined:
    Oct 10, 2015
    Posts:
    3
    hello,
    i have followed the tutorials up to where im getting my shot to fire so i shoot it and it stops at the boundary what do i do?! someone helo please!
     
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Riiiiiiiiight. Didn't think of score. Like I said, I did that out of my back pocket without testing, but yes, the score can only be updated when the hazard is destroyed.... Unless you want game play that awards the player per hit!

    Can you post your script? This one I've posted should work with different explosions... What's failing?
     
  10. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thank you!
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    C
    Can you please give us more detailed information?
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is not related to this thread. Can you post in scripting and tag me with @Adam Buckner so I can answer there?
     
    Last edited: Oct 12, 2015
  13. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    Here it is:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class DestroyByContactWithHealth : MonoBehaviour
    5. {
    6.  
    7.     public GameObject explosion;
    8.     public GameObject playerExplosion;
    9.     public int scoreValue;
    10.     public int health;
    11.     public GameObject smallExplosion;
    12.     private Done_GameController gameController;
    13.    
    14.     void Start ()
    15.     {
    16.         GameObject gameControllerObject = GameObject.FindGameObjectWithTag ("GameController");
    17.         if (gameControllerObject != null)
    18.         {
    19.             gameController = gameControllerObject.GetComponent <Done_GameController>();
    20.         }
    21.         if (gameController == null)
    22.         {
    23.             Debug.Log ("Cannot find 'GameController' script");
    24.         }
    25.     }
    26.  
    27.     void OnTriggerEnter (Collider other)
    28.     {
    29.         if (other.tag == "Boundary" || other.tag == "Enemy")
    30.         {
    31.             return;
    32.         }
    33.        
    34.         // Add DECREMENT here:
    35.         health -= 1;
    36.        
    37.  
    38.  
    39.         if (explosion != null)
    40.         {
    41.             if (health <=0)
    42.             {
    43.                 Instantiate (explosion, transform.position, transform.rotation);
    44.             }
    45.             else
    46.             {
    47.                 Instantiate (smallExplosion, transform.position, transform.rotation);
    48.             }
    49.         }
    50.        
    51.         if (other.tag == "Player")
    52.         {
    53.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    54.             gameController.GameOver();
    55.         }
    56.        
    57.                
    58.         // Add TEST here:
    59.         if (health <= 0)
    60.         {
    61.             Destroy (gameObject);
    62.             gameController.AddScore (scoreValue);
    63.             Destroy (other.gameObject);
    64.         }
    65.     }
    66.    
    67.  
    68. }

    there is one more problem. When hazards health > 0 the bullets fly through the hazard, but it should not. It looks strange.

    Adam, while you are here could I ask you one more question. Here is a gamecontroller script where after some number of waves I spawn the one last hazard (the boss). There is one problem: if boss kills the player first the text = "Press 'R' for Restart" never appears. Could you tell me what to do to fix it?

    Code (CSharp):
    1.     IEnumerator SpawnWaves ()
    2.     {
    3.         yield return new WaitForSeconds (startWait);
    4. //        while (!gameOver)   //для бесконечного колличества волн, надо еще убрать ниже break
    5.         while(countOfWaves > 0)
    6.         {
    7.             for (int i = 0; i < hazardCount; i++)
    8.             {
    9.                 GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    10.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    11.                 Quaternion spawnRotation = Quaternion.identity;
    12.                 Instantiate (hazard, spawnPosition, spawnRotation);
    13.                 yield return new WaitForSeconds (spawnWait);
    14.             }
    15.             yield return new WaitForSeconds (waveWait);
    16.             countOfWaves--; //счётчик волн
    17.  
    18.             if (countOfWaves == 0)//spawn the boss
    19.             {
    20.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    21.                 Quaternion spawnRotation = Quaternion.identity;
    22.                 Instantiate (boss, spawnPosition, spawnRotation);
    23.             }
    24.  
    25.             if (gameOver)
    26.             {
    27.                 restartText.text = "Press 'R' for Restart";
    28.                  restart = true;
    29.                 break;
    30.             }
    31.         }
    32.     }
    33.  
    34.     public void AddScore (int newScoreValue)
    35.     {
    36.         score += newScoreValue;
    37.         UpdateScore ();
    38.     }
    39.  
    40.     void UpdateScore ()
    41.     {
    42.         scoreText.text = "Score: " + score;
    43.     }
    44.  
    45.     public void GameOver ()
    46.     {
    47.         gameOverText.text = "Game Over!";
    48.         gameOver = true;
    49.     }
    50.  
    51. }
    and very last question:) Could you tell me how to stop enemy's shooting when player is dead (and GAME OVER text appears)
    Once againe thank you for your amazing tutorial and answers :)
     
    Last edited: Oct 10, 2015
  14. whiteskull24

    whiteskull24

    Joined:
    Oct 10, 2015
    Posts:
    3
    to be more recent and accurate i just finished the 11th tutorial, and i have my asteroid set and in the prefab folder, as well i have removed the main list. like it says in the tutorial but i cannot get the asteroid to spawn and i have checked my code five times over.
     
  15. Mikesblaack

    Mikesblaack

    Joined:
    Jun 10, 2015
    Posts:
    1
    Hi,
    I can't load the tile nebula green on to the scene with drag and drop. What will I need to do?
    Thanks,
    Mike

    [Removed useless quote of the first post... - Moderator]
     
    Last edited by a moderator: Oct 12, 2015
  16. shintaru22

    shintaru22

    Joined:
    Oct 4, 2015
    Posts:
    10
    sir SicraS thank a lot for your help ..its working although i change some of the code in the code you share..my problem now is how to end it and go to next level.. thank you again sir SicraS.. :)
     
    SicraS likes this.
  17. Wanderevil

    Wanderevil

    Joined:
    Nov 8, 2014
    Posts:
    8
    Hello! I have a problem on Game Controller script. The supposed hazards aren't spawning randomly, but only spawns on the same area.

    I followed everything and had troubleshoot the code, but can't find the culprit of the error. The code below:
    Code (CSharp):
    1. public GameObject hazard;
    2. public Vector3 spawnValues;
    3.  
    4.     void Start()
    5.     {
    6.         SpawnWaves ();
    7.     }
    8.     void SpawnWaves()
    9.     {
    10.         Vector3 spawnPostion = new Vector3 (Random.Range(-spawnValues.x, -spawnValues.x), spawnValues.y,   spawnValues.z);
    11.         Quaternion spawnRotation = Quaternion.identity;
    12.         Instantiate (hazard, spawnPostion, spawnRotation);
    13.     }
    Any help will be appreciated! Also the link to the episode of the tutorial -
     
  18. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening @Wanderevil,

    where you currently have
    Code (CSharp):
    1.  Vector3 spawnPostion = new Vector3 (Random.Range(-spawnValues.x, -spawnValues.x), spawnValues.y,   spawnValues.z);
    you need to change your second spawnValues.x to be a positive, otherwise it will always be on the left hand side as there will be no difference in the two values for Random.Range to give values for.
    change to:
    Code (CSharp):
    1. Vector3 spawnPostion =newVector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y,   spawnValues.z);
    Should be good to go then ;)
     
  19. Wanderevil

    Wanderevil

    Joined:
    Nov 8, 2014
    Posts:
    8
    @OboShape Thank you man! Now I feel dumb for not noticing it D:
     
  20. FunkyTeaC

    FunkyTeaC

    Joined:
    Oct 10, 2015
    Posts:
    3
    Hello, so. i am in the issue of when pressing fire1 (left mousebutton) after putting my bolt into and shootspawn into the player controller "boundary", the bolt doesn't appear visible on my screen when i play.

    It pops up in the hierachy as a active object when i press fire1. but it isn't visible ingame. can't quite figure out what i've done wrong here.. it Works when i drag and drop it from prefabs. (right not it is only connected through player controller and the corresponding script. and bolt is not permanently placed in the hierachy.

    Shotspawn only have Transform in it. a last Picture will follow in a reply to this post. which will be the VFX inspector
    Not sure why my bolt isn't visible when i press fire1. (as mentioned above, it does appear in the hierachy when i play and press fire1. it just isn't visible)

    Bolt inspector.jpg Mover script.jpg Player controller scripts 1-2.jpg Player controller script 2-2.jpg Player inspector.jpg
     
  21. FunkyTeaC

    FunkyTeaC

    Joined:
    Oct 10, 2015
    Posts:
    3
    VFX inspector.jpg
    This is the last picture
     
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Ok: I'll see what I can do to help out but:

    This is beginning to rearchitect this game to a point where some (if not many) of the very simple arrangements will begin to fail, and the game will need to be completely redesigned.

    I don't see what the problem would be with the explosions with that script... perhaps you can remind me of the details? It looks like you'll get the small explosions when the hazard has health > 0, and the (big) explosion when health <= 0. What's not working?

    Remember that this destroy by contact script is being used by several objects, so it's beginning to get complicated. There is even the code:
    Code (csharp):
    1.   if (explosion != null)
    2.         {
    3.         }
    ... to make it work with the enemy bolts destroying the player. This is a tiny bit of a hack. This was to keep the game very simple and let the hazards drive the logic. (This code [the if (explosion...] was put there so there could be a "DestroyByContact" script on the enemy's bolt to destroy the player, iirc.)

    If you want to get into having the bolts control the damage and destruction of the hazards, and the hazards (and enemy bolts) controlling the destruction of the player, you will need more complex logic. You'd probably need to get into different destruction scripts on the bolts and hazards. The easiest way to do this is just to write custom logic for each item and make sure that they don't conflict. You get one advantage, which is if you use Destroy() then this doesn't actually remove the GameObject from the scene, but it marks or flags the GameObject to be destroyed at the end of the frame. This means you can Destroy the same GameObject multiple times in the same frame and it won't cause too much trouble. The proper way might be to write one base script for DestroyByContact and then to derive additional custom scripts for the children using Inheritance (see the Learn site or a C# tutorial to learn more about inheritance).

    Well, you'll have to look at your logic here... This is because you've wrapped Destroy (other.gameObject); inside if (health <= 0), so it can't be accessed. So, this will have to be rethought. Perhaps you'll need to remove the entire concept of DestroyByContact and implement a Damage function. Maybe a DamageByContact? Every object will have to have a Damagable script on it (and you may slowly want to look at something called Interfaces here), or a Health script. And that script has a public int health; variable and a public void TakeDamage(int damageValue) function that has logic where health -= damageValue; and then what to do if (health <= 0) {}. This may need to be different depending upon what GameObject it is on (which is why Interfaces might be useful!) and then in OnTriggerEnter() you will need to cause damage. You will have to experiment on who controls the collision. Perhaps every GameObject does damage to the other.GetComponent<Health>().TakeDamage(damageValue); and then do nothing about themselves, and let the other object damage them back?? You'd have to play with it and see what works best for you.

    This is probably related to how GameOver() is called. Isn't this currently controlled by the hazard? With an if(other.CompareTag("Player")? In the implementation of the Boss killing the Player, does the Boss call GameOver()? Who in the end-game calls this:
    Code (csharp):
    1.     public void GameOver ()
    2.     {
    3.         gameOverText.text = "Game Over!";
    4.         gameOver = true;
    5.     }
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    So, I'm confused now...

    Did you solve the issue with the bolts not leaving the boundary? Or is this still an issue?

    This new issue, not being able to get your hazards (the asteroids) to spawn, can you give more detailed information?

    Can you look at the other people who are posting questions here and look at how they are doing it? They are posting code, screenshots and other details that let us help figure out the problem.

    If you were a car mechanic and I came into your garage and asked: "Hey, my car doesn't work. I left it at home and walked here to your garage. Can you please tell me what's wrong with my car?" What would you say to me and how would you fix my car?
     
  24. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    First, you'll need to give us A LOT more information! See my note about the car mechanic in the post above this one!

    If you follow the steps in the video, you should be able to load the nebula with drag and drop. There are also other ways to use the image texture.

    Can you please tell us when and how this is failing and what steps you are taking?

    First suggestion would actually be, rewatch the video and redo all of the steps.
     
  25. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @Wanderevil I'm glad you got it working. @OboShape Sharp eyes! Thanks!
     
  26. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Should this be "transform.up" in this code:
    TransformUp.png

    or should it be:
    Code (csharp):
    1. rb.velocity = transform.forward * speed;
    This is just from memory, so you should check this against the code posted on the webpage related to this episode, or against the code in your "Done" folder.
     
    OboShape likes this.
  27. shintaru22

    shintaru22

    Joined:
    Oct 4, 2015
    Posts:
    10
    sir Adam Buckner can you help me again. i got now how to limit the enemies but i dont know how to end it and show her/his score in level.. thank you. :)
     
  28. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Sorry, I might be a little slow here... Can you give me the full details? "How to end it"... How to end what?

    Let me know exactly what you want to do, and I'll try to give you a hand.
     
  29. shintaru22

    shintaru22

    Joined:
    Oct 4, 2015
    Posts:
    10
    example is i have 50 enemies and i kill them all already how i will gonna show my score just like this.
     
  30. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Well, think it through:

    • You will need a new ui text element to display your score.
    • You will need a new ui panel to hold your text element.
    • You will need a way of turning the panel (and it's child text element) on and off.
    • You will need to do this when the spawn loop is over.

    Now, this is all assuming you are keeping the same analogy of working in one simple scene.

    I would:
    • Create a new ui panel
    • Create a new ui text element
    • Create a variable to hold a reference to the panel
    • Create a variable to hold a reference to the text element
    • Start with the panel "turned off" (eg: GameObject is inactive)
    • Find the correct spot in my code to turn on the panel and set the score value
    • Write the code to use the reference to panel and turn it on
    • Write the code to use the reference to the text element to set the score
    Does this make sense? Is this enough for you to get started?
     
  31. shintaru22

    shintaru22

    Joined:
    Oct 4, 2015
    Posts:
    10
    yes sir i will follow that thank you sir.
     
  32. DYV

    DYV

    Joined:
    Aug 10, 2015
    Posts:
    58
    Adam, thank you very much for your answers about health implementation to the game. Now all things are working good ( I added damageValue to the bullets etc)

    Yes, the Boss calls GameOver by destroyByContact script (as any other hazards). And "Game Over" appears on the screen. It works. But since count of waves = 0 the text "Press 'R' for Restart" is not going to be called. This is happen only if the Boss kills the player. My question is: what would you suggest me to fix it? I suppose that it should be additional script for boss (or player?) but alas, as I said I am not a programmer. The answer could help me with another my question: how to stop enemy's shooting when player is dead? Please:)
     
    Last edited: Oct 12, 2015
  33. boylamn

    boylamn

    Joined:
    Jan 28, 2015
    Posts:
    19
    Hi,
    I have created a new scene in the game that hold "game Over" UI text with a button to replay, so when the player is destroyed this level is then loaded.
    Everything is working fine except the fact that my new scene is loaded quickly when the player is destroyed, even the explosion isn't shown. I tried to fix that by adding a function to the "Game Controller" script :
    Code (CSharp):
    1. public IEnumerator Wait()
    2.     {
    3.         yield return new WaitForSeconds(2);
    4.     }
    and calling it in StartCoroutine() inside GameOver() function :
    Code (CSharp):
    1. public void GameOver()
    2.     {
    3.    
    4.         StartCoroutine(Wait());
    5.         Application.LoadLevel("Lose Menu");
    6.      
    7.         gameOver = true;
    8.  
    9.     }
    But it's not working :( So it seems I need some help:).
     
  34. Oscaruzzo

    Oscaruzzo

    Joined:
    Jan 26, 2015
    Posts:
    17
    Your Wait() function is running in background. That's exactly what coroutines do. So you start you coroutine and while it runs you load the "Lose Menu" level. Then, after two seconds, the Wait routine ends and that does nothing at all.

    You should probably move Application.LoadLevel in your Wait method.

    Code (CSharp):
    1. public IEnumerator Wait() {
    2.     yield return new WaitForSeconds(2);
    3.     Application.LoadLevel("Lose Menu");
    4. }
    5.  
    6. public void GameOver() {
    7.     StartCoroutine(Wait());
    8.     gameOver = true;
    9. }
    10.  
    Or you could just write something like this (which should be exactly equivalent, as far as I know)

    Code (CSharp):
    1. public void LoadMenu() {
    2.     Application.LoadLevel("Lose Menu");
    3. }
    4.  
    5. void GameOver() {
    6.     gameOver = true;
    7.     Invoke("LoadMenu", 2.0f);
    8. }
    That will call "LoadMenu" after two seconds.
     
    Last edited: Oct 12, 2015
  35. boylamn

    boylamn

    Joined:
    Jan 28, 2015
    Posts:
    19
    Thanks man. this was very helpful.
     
    Oscaruzzo likes this.
  36. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Well, it is just logic.

    How about making a cup of tea?



    Code (CSharp):
    1.     IEnumerator SpawnWaves ()
    2.     {
    3.         yield return new WaitForSeconds (startWait);
    4. //        while (!gameOver)   //для бесконечного колличества волн, надо еще убрать ниже break
    5.         while(countOfWaves > 0)
    6.         {
    7.             for (int i = 0; i < hazardCount; i++)
    8.             {
    9.                 GameObject hazard = hazards [Random.Range (0, hazards.Length)];
    10.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    11.                 Quaternion spawnRotation = Quaternion.identity;
    12.                 Instantiate (hazard, spawnPosition, spawnRotation);
    13.                 yield return new WaitForSeconds (spawnWait);
    14.             }
    15.             yield return new WaitForSeconds (waveWait);
    16.             countOfWaves--; //счётчик волн
    17.  
    18.             if (countOfWaves == 0)//spawn the boss
    19.             {
    20.                 Vector3 spawnPosition = new Vector3 (Random.Range (-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    21.                 Quaternion spawnRotation = Quaternion.identity;
    22.                 Instantiate (boss, spawnPosition, spawnRotation);
    23.             }
    24.  
    25.             if (gameOver)
    26.             {
    27.                 restartText.text = "Press 'R' for Restart";
    28.                  restart = true;
    29.                 break;
    30.             }
    31.         }
    32.     }
    Right... so the last thing you do in the Coroutine is spawn the boss and then the coroutine is done...

    You're either going to have to find a way to do this INSIDE the coroutine (another loop?) or remove the game over code from inside the coroutine, put it in it's own function, and call that when the boss kills the player as well as when it's in the coroutine.
     
    OboShape likes this.
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    With that code you are simply Starting the coroutine, not waiting for it.

    You need to make the GameOver() function the IEnumerator.

    Try:
    Code (CSharp):
    1.  
    2. public float gameOverWait = 2.0f;
    3.  
    4. public IEnumerator GameOver()
    5.     {
    6.  
    7.         yield return new WaitForSeconds(gameOverWait);
    8.         Application.LoadLevel("Lose Menu");
    9.    
    10.         gameOver = true;
    11.  
    12.     }
    ps: Why is GameOver() public? Does it need to be accessed outside of this script? If not, make it private! (You can do this by removing "public".)
     
  38. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Whoops! Thanks!

    You already answered it!

    I didn't read ahead before I answered it as well, thanks!
     
    Oscaruzzo likes this.
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    SicraS likes this.
  40. Deleted User

    Deleted User

    Guest

    Can I have a full list of code where it works in Unity5? Its not counting points. The player movement control no longer works. The "asteroids" will not appear anywhere else and spawn in the same location. I changed GameController from private to public but its still not referencing things properly.

    Here is the three problems.

    Player movement when it comes to tilt or locking in place wont work, in fact none of the thing works, so i put this one in and it works. I would like a full update of this so it functions properly as i keep getting the call on Rigid body as out of date or obsolete.

    .
    public class PlayerMovement : MonoBehaviour {

    public float moveSpeed = 45.0f;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    transform.Translate(moveSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, moveSpeed * Input.GetAxis("Vertical") * Time.deltaTime);


    }
    }


    Second. There is a problem with both the Game controller script under add points and the asteroids keep spawning in the same point destroying one another. Again I would like a full copy of the updated code so it works properly.



    using UnityEngine;
    using System.Collections;

    public class DestroyByContact : MonoBehaviour
    {
    public GameObject explosion;
    public GameObject playerExplosion;
    public int scoreValue;
    public GameController gameController;

    void Start()
    {
    GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    if (gameControllerObject != null)
    {
    gameController = gameControllerObject.GetComponent<GameController>();
    }
    if (gameController == null)
    {
    Debug.Log("Cannot find 'GameController' script");
    }
    }

    void OnTriggerEnter(Collider other)
    {
    if (other.tag == "Boundary")
    {
    return;
    }
    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 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))
    {
    Application.LoadLevel(Application.loadedLevel);
    }
    }
    }

    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;
    }
    }

    These are the errors im getting because of this all.

    Cannot find 'GameController' script
    UnityEngine.Debug:Log(Object)

    NullReferenceException: Object reference not set to an instance of an object
    DestroyByContact.OnTriggerEnter (UnityEngine.Collider other) (at Assets/DestroyByContact.cs:34)
     
    Last edited by a moderator: Oct 14, 2015
  41. shintaru22

    shintaru22

    Joined:
    Oct 4, 2015
    Posts:
    10
    {
    yield return new WaitForSeconds (startWait);
    // Number of waves to Spawn
    int wavesNumber = 50; // This surely needs to be a public attribute of the class so you can set its value in the editor
    // counter which counts the waves
    int wavesCount = 0; // We initialize it to zero
    // now we will loop until the wavesCount = 50
    while (wavesCount < wavesNumber) // this will evaluate to false when wavesCount = 50
    {
    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);

    // now we add 1 to our counter so the condition could be false
    wavesCount++;
    }
    }

    ...sir why sir Adam Buckner that the loop is not end.. when the 50 enemies is already shown the loop of enemies is show again after a few seconds..
     
  42. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I really don't understand what you need.

    First:
    Can you please learn to use code tag properly?

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

    Second: when the code is formatted, can you clearly state what the issues are?
     
    Oscaruzzo likes this.
  43. 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/
     
    Oscaruzzo likes this.
  44. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Sorry, guys, but if you can't format your code, I really can't decipher it.
     
    SicraS and OboShape like this.
  45. shintaru22

    shintaru22

    Joined:
    Oct 4, 2015
    Posts:
    10
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
  47. SicraS

    SicraS

    Joined:
    Sep 22, 2015
    Posts:
    7
  48. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Strange, seems to be working now...
     
  49. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  50. Algoriddem

    Algoriddem

    Joined:
    Jul 3, 2015
    Posts:
    2
    My boundary code doesn't seem to be working (as in it is not there), is there an error with my coding or am I just doing something wrong? Any help would be much appreciated. P.s I am using unity 5.1 if that helps lol.

    upload_2015-10-15_21-3-59.png