Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Space Shooter Tutorial Q&A

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

  1. hayleywarriner

    hayleywarriner

    Joined:
    Mar 13, 2018
    Posts:
    3
    PLEASE HELP THIS IS DRIVING ME CRAZY.
    I have checked and rechecked all of my code and every time I go into game mode, my astroid destroys itself and there's nothing left. It worked one time then went back to it the next time I played. I've gone through the video "Explosions," and have REgone through everything. This is my code for DestroyByContact

    using UnityEngine;
    using System.Collections;

    public class DestroyByContact : MonoBehaviour
    {
    public GameObject explosion;
    public GameObject playerexplosion;

    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);
    }
    Destroy(other.gameObject);
    Destroy(gameObject);
    }
    }

    Please help me.
     
  2. Andy_mantis

    Andy_mantis

    Joined:
    Mar 15, 2018
    Posts:
    2
    Hi all!

    I've been having an issue with my boundary interacting with the asteroid. Even though I have the bellow code on the asteroid gameobject, the boundary continues to destroy it.

    Code (CSharp):
    1. public class DestroyByContact : MonoBehaviour {
    2.  
    3.     void OnTriggerEnter(Collider other) {
    4.         Debug.Log(other.name);
    5.         if (other.tag == "Boundary")
    6.         {
    7.             return;
    8.         }
    9.  
    10.             Destroy(other.gameObject);
    11.             Destroy(gameObject);
    12.     }
    13.  
    14. }
    15.  
    Thanks!
     
  3. hayleywarriner

    hayleywarriner

    Joined:
    Mar 13, 2018
    Posts:
    3
    ME TOO. If you find a solution, PLEASE let me know!
     
  4. Andy_mantis

    Andy_mantis

    Joined:
    Mar 15, 2018
    Posts:
    2
    SOLVED IT. Check the scale of your boundary transform in Y! mine was set to 1 so when the asteroid rotated, it immediately hit the boundary and was destroyed.
     
  5. hayleywarriner

    hayleywarriner

    Joined:
    Mar 13, 2018
    Posts:
    3
    Okay, I'm ALMOST DONE with the mobile video but as soon as I write GetFire in the PlayerController script, every time I get an error in unity that says "Assets/Scripts/PlayerController.cs(40,18): error CS1061: Type `SimpleTouchAreaButton' does not contain a definition for `canFire' and no extension method `canFire' of type `SimpleTouchAreaButton' could be found. Are you missing an assembly reference?"
    Same thing for GetDirection, even though that worked earlier.
    I can't move on without getting this fixed, so someone PLEASE HELP.
     

    Attached Files:

  6. Ni_iQ

    Ni_iQ

    Joined:
    Feb 8, 2018
    Posts:
    1
    THIS IS for guys ?who learning bySpace Shooter tutorial2017yers + .In the video "Counting points and displaying the score" need to use UI Text(NOT GUIText) Безымянный2.png
    and in the GameController script ,

    correct the code on line 4 and 13 as shown in the picture(line 4:"using UnityEngine.UI;" line 13:"public Text scoreText;")
    Безымянный.png
     
  7. DigitalProgramer

    DigitalProgramer

    Joined:
    Mar 19, 2018
    Posts:
    3
    In 4:53 he comments about web player but that option do not exist anymore. I looked in the web and the page below said that it could be substitute by webGL.

    https://unity3d.com/pt/webplayer

    I hope that help someone!
     
    DarKing9 and yeungjasonj like this.
  8. Shnuckles

    Shnuckles

    Joined:
    Mar 25, 2018
    Posts:
    2
    I'm trying to expand on the game by making a second type of projectile to fire ate the enemy. This time the projectile would be heatseeking and would seek out the asteroids. Any idea on how I would go about importing this feature?
     
  9. frostygreenacre

    frostygreenacre

    Joined:
    Mar 25, 2018
    Posts:
    2
    Hello everyone. I'm seriously stuck on Lesson 5 trying to get the ship moving. I've gone back as far as page 57 on here and have seen comebody suggest I change the "rb.velocity = movement * speed;" to "GetComponent<Rigidbody> ().velocity = movement * speed;" But that doesn't seem to work and I haven't seen a subsequent answer from the original guy asking the question.

    I've added the below code, but I'm getting no movement whatsoever. I've also tried stealing the code from the completed version, but that doesn't appear to move the ship either. Is it possible there's some option outside of the scripting I'm missing? Gravity is switched off for the rigid body and it is not set to kinematic (although I tried switching those around to no effect) Thanks in advance!

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

    Ramalamafizzfaj

    Joined:
    Mar 27, 2018
    Posts:
    1
    I've fixed this by doing like this
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class PlayerController : MonoBehaviour {
    7.     public Rigidbody rb;
    8.  
    9.     void FixedUpdate()
    10.     {
    11.         float moveHorizontal = Input.GetAxis("Horizontal");
    12.         float moveVertical = Input.GetAxis("Vertical");
    13.  
    14.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    15.         rb.velocity = movement;
    16.     }
    17. }
    18.  
    Then, in the inspector on your player game object, click and drag the rigidbody from the components list into the box for it on the script (also in your components list)

    that will get you moving.
     
    frostygreenacre likes this.
  11. frostygreenacre

    frostygreenacre

    Joined:
    Mar 25, 2018
    Posts:
    2
    This worked perfectly, thanks!
     
  12. andrewdbanks

    andrewdbanks

    Joined:
    Feb 4, 2014
    Posts:
    27
    As stated back in November in this thread, the explosion effects are broken on the latest version of Unity because, under Emissions in the particle effects, "Bursts" was renamed to "Count", and that value is now initialized to 0 in the conversion. Please update the upgrade guide to provide steps for this so that we can get the explosions working off of this tutorial still. I set all of my "Count"s to 100, which may be spending more resources than I need to, but I'm not really sure what I'm doing when it comes to particle effects. Either way, I get explosions now, and it seems to look a lot like the tutorial video.
     
  13. DAKSHDD

    DAKSHDD

    Joined:
    Apr 4, 2018
    Posts:
    2
    hey adam please can you help mewith this script in space shooter as its showing an error everytime i hit play
    using UnityEngine;
    using System.Collections;

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

    public class PlayerController : MonoBehaviour
    {
    public float speed;
    public float tilt;
    public Boundary boundary;

    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

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

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

    rigidbody.rotation = Quaternion.Euler (0.0f, 0.0f, rigidbody.velocity.x * -tilt);
    }
    }
     
  14. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    381
    Ok. This is really bad, I need to write here about it:

    I'm starting tutorials for v5.6. I can't use 2017 or 2018 because I have lots of clients that still use 5.6.

    "This project is designed to work with the Space Shooter tutorial Project on Unity's Tutorial area. Visit the tutorial here. Note: Updated and compatible with Unity 5.x"

    But I can't download the tutorials made for v5 like this one because it's been updated in the asset store and it needs v2017... even when It's not updated to those versions. Not the videos, not the contents or the update guide.
    It makes no sense.


    Can somebody explain how to get the older assets, please? Because we can't do the tutorial in v5 now. It's really silly that I can't do it now.
     
  15. PrometheusGames

    PrometheusGames

    Joined:
    Apr 9, 2018
    Posts:
    1
    I have done the tutorial and the extended tut. So, my question is, is there a tut to show us how to add health to the enemies? How about changing the assets to our own assets and make it our own unique game?
     
  16. Littlemc444

    Littlemc444

    Joined:
    Apr 17, 2018
    Posts:
    1
    when i code the part with spawning the objects i have wrote the code correctly but the object does not spawn on the screen any help?
     
  17. Nanonukes

    Nanonukes

    Joined:
    Apr 13, 2018
    Posts:
    1
    Hello everyone,

    after finishing the script "DestroyByContact" i have noticed something that i still can't understand, when we initialize the variable:

    Code (CSharp):
    1.     private GameController gameController;
    what is the GameController class? shouldn't it be a GameObject class that contains the GameController script? I don't understand how Unity can consider the variable gameController as a GameController class. Anyone could please explain how this works?

    Thanks in advance.
     
  18. jnoko

    jnoko

    Joined:
    Dec 26, 2015
    Posts:
    1
    Working on Space Shooter Tutorial. Just started Section 05 Moving the Player and encountered a problem. My player does not move and I encountered these error messages in my script. Not sure what went wrong. Help!!!
    Screen Shot 2018-04-20 at 3.55.27 PM.png
     
  19. derek25888

    derek25888

    Joined:
    Apr 23, 2018
    Posts:
    5
    My problem is that I can't control my ship.
    On Unity, they say that "float" is an unexpected symbol.
    Could you help me please?
     
  20. derek25888

    derek25888

    Joined:
    Apr 23, 2018
    Posts:
    5
    :oops: Forget it.

    :eek: I have a new problem : " Assets/Scripts/PlayerController.cs(4,33): error CS0246: The type or namespace name `Monobehaviour' could not be found. ". :eek:


    o_O:confused: And after that, they ask me this question : " Are you missing an assembly reference? ". o_O:confused:


    :( How can I fix it ?
     
  21. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,042
    Okay...
    1). DO provide enough information for people to help you. Provide the full error which should include a line number. Provide the code (using code tags) you have that is relative to the problem. List what you tried and what hasn’t/ has worked.

    2). DO NOT repeat your request every five minutes. You need to (give it at least 24 hours). People need time to respond, this is community support, not a help desk. Be patient.

    3). BE POLITE don’t fill your post with emojis as bold demanding text, please act like an adult. Ranting isn’t going to encourage anyone to bother helping you. (I have removed your other pointless demanding posts).

    If you are clear, concise an polite, people may be willing to help. Otherwise it will get ignored. If you want help, be respectful.
     
    derek25888 likes this.
  22. clabtl

    clabtl

    Joined:
    Apr 15, 2018
    Posts:
    4
    Help please :)

    Hi everyone, I'm on step 14 of the tutorial and two things seem to be happening.

    1.
    Im getting the error "Object reference not set to an instance of an Object" referencing to GameController.UpdateScore (). The script looks like this:

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

    Also: I can't drag the Score Text element from the hierarchy panel to the 'Score Text' field on the 'Game Controller (script)' panel inside the 'Game Controller' element. It's one of the last things done on the 14th step video.

    2.
    No asteroids are showing up when I'm hitting play, and this started happening during this step of the tutorial.

    Let me know if you need more info.

    Thanks in advance
     
  23. clabtl

    clabtl

    Joined:
    Apr 15, 2018
    Posts:
    4
  24. derek25888

    derek25888

    Joined:
    Apr 23, 2018
    Posts:
    5
  25. clabtl

    clabtl

    Joined:
    Apr 15, 2018
    Posts:
    4
    There's something that helped me: there's a "Done" or "Complete" folder with the content that was downloaded in the pack. Open and look for the "Scripts" folder. Compare the code with the code you typed. Many mistakes of mine were just typing errors.

    p.s.: The 'Done' scripts are complete, so they might have more code than you typed. Just scroll and look for the parts you already have and compare only them. Good luck!

     
  26. BladeRunner0

    BladeRunner0

    Joined:
    Apr 29, 2018
    Posts:
    1
    Hello
    I have a problem at the playercontroller script: I am using Virtual Studio because I can't run MonoDevelop and I don't understand where I did a mistake. This is my script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour
    {
    private Rigidbody rb;
    void Start()
    {
    rb = GetComponent<Rigidbody>();
    }

    void FixedUdpate()
    {
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(moveHorizontal, 0.0F, moveVertical);
    NewMethod(moveHorizontal, moveVertical);
    }

    private void NewMethod(float moveHorizontal, float moveVertical)
    {
    rb.rotation = Quaternion.Euler(moveHorizontal, 0.0F, moveVertical);
    }
    }

    Thank for repplying
     
  27. meghanejack

    meghanejack

    Joined:
    Apr 26, 2018
    Posts:
    1
    Hey all! I was struggling with the script for getting the ship to move but I think I finally figured it out. The script for moving the player should be this now
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     private Rigidbody rb;
    13.  
    14.     private void Start()
    15.     {
    16.         rb = GetComponent<Rigidbody>();
    17.     }
    18.     public float speed;
    19.     public float tilt;
    20.     public Boundary boundary;
    21.  
    22.     void FixedUpdate()
    23.     {
    24.         float moveHorizontal = Input.GetAxis("Horizontal");
    25.         float moveVertical = Input.GetAxis("Vertical");
    26.  
    27.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    28.         rb.velocity = movement * speed;
    29.  
    30.         rb.position = new Vector3
    31.         (
    32.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    33.             0.0f,
    34.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    35.         );
    36.  
    37.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    38.     }
    39. }
    Hope this helps some people out!
     
  28. Salenah

    Salenah

    Joined:
    Dec 20, 2017
    Posts:
    3
    Hi, I'm currently working on the Creating Hazards tutorial and everything seems to work as it should, except when I fire a shot at the asteroid, the shot and asteroid are both destroyed instantly. I do not see the shot move toward the asteroid, only a bit of a flash out the front of my ship just before both objects are destroyed. I checked the size of the colliders but they seem to be fine. The other shots perform normally firing off to the boundary. I'm using 2017. Any ideas on where to look to fix this would be greatly appreciated.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyByContact : MonoBehaviour {
    6.  
    7.     void OnTriggerEnter(Collider other)
    8.     {
    9.         if (other.tag == "Boundary")
    10.         {
    11.             return;
    12.         }
    13.         Destroy(other.gameObject);
    14.         Destroy(gameObject);
    15.     }
    16. }
    17.  
    Edited to add: After a night's sleep I have re-watched the videos on Boundaries, shots, and creating hazards. I'm still having the problem. I've double checked the sizes of my mesh colliders (I had thought perhaps the bolt collider was too long and hitting the asteroid on spawn but that doesn't seem to be the case.), and am currently still searching for a fix. I'm currently reading up the instantiate material because maybe that's where the problem is, which would make it a different script.
     
    Last edited: May 2, 2018
  29. Salenah

    Salenah

    Joined:
    Dec 20, 2017
    Posts:
    3
    Decided to make a new post because I think I have narrowed it down to the shotspawn. Even when I move the player ship off to one side the asteroid is destroyed which means that it is happening when the shot enters the game. I'm thinking maybe I have an error translating from v4 to 2017 that I just haven't managed to find yet.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [System.Serializable]
    4. public class Boundary
    5. {
    6.     public float xMin, xMax, zMin, zMax;
    7. }
    8.  
    9. public class PlayerController : MonoBehaviour
    10. {
    11.     public float speed;
    12.     public float tilt;
    13.     public Boundary boundary;
    14.     public Rigidbody rb;
    15.  
    16.     public GameObject shot;
    17.     public Transform shotSpawn;
    18.     public float fireRate;
    19.  
    20.     private float nextFire;
    21.  
    22.     void Start()
    23.     {
    24.         rb = GetComponent<Rigidbody>();
    25.     }
    26.  
    27.      void Update()
    28.     {
    29.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    30.         {
    31.             nextFire = Time.time + fireRate;
    32.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    33.         }
    34.     }
    35.  
    36.     void FixedUpdate()
    37.     {
    38.         float moveHorizontal = Input.GetAxis("Horizontal");
    39.         float moveVertical = Input.GetAxis("Vertical");
    40.  
    41.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    42.         rb.velocity = movement * speed;
    43.  
    44.         rb.position = new Vector3
    45.         (
    46.             Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax),
    47.             0.0f,
    48.             Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax)
    49.         );
    50.  
    51.         rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
    52.     }
    53. }
    EDIT: I believe the problem was created because I forgot to remove the mesh collider from the VFX object.
     
    Last edited: May 6, 2018
  30. angus051224

    angus051224

    Joined:
    May 6, 2018
    Posts:
    1
    I can't find web player platform. (unity 2017.4.2f2 personal 64bit )
     
  31. Salenah

    Salenah

    Joined:
    Dec 20, 2017
    Posts:
    3
    I have 2017.3 and you didn't say if you are using PC or MAC but on the PC it's under File>Build Settings>WebGL.
     
  32. derek25888

    derek25888

    Joined:
    Apr 23, 2018
    Posts:
    5
    The script I used is this one :
    _____________________________________________________________________________________________
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class Boundary
    6. {
    7.     public float xMin, xMax, zMin, zMax;
    8. }
    9.  
    10. public class PlayerController : MonoBehaviour
    11. {
    12.     public float speed;
    13.     public float tilt;
    14.     public Boundary boundary;
    15.  
    16.     public GameObject shot;
    17.     public Transform shotSpawn;
    18.     public float fireRate;
    19.  
    20.     private float nextFire;
    21.  
    22.     void Update ()
    23.     {
    24.         if (Input.GetButton("Fire1") && Time.time > nextFire)
    25.         {
    26.             nextFire = Time.time + fireRate;
    27.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
    28.             GetComponent<AudioSource>().Play ();
    29.         }
    30.     }
    31.  
    32.     void FixedUpdate ()
    33.     {
    34.         float moveHorizontal = Input.GetAxis ("Horizontal");
    35.         float moveVertical = Input.GetAxis ("Vertical");
    36.  
    37.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    38.         GetComponent<Rigidbody>().velocity = movement * speed;
    39.  
    40.         GetComponent<Rigidbody>().position = new Vector3
    41.             (
    42.                 Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
    43.                 0.0f,
    44.                 Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
    45.             );
    46.  
    47.         GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);
    48.     }
    49. }
    50.  
    _____________________________________________________________________________________________
    And it does not work because I cannot move my ship.
    I wonder why ...
    If you know, please write back.
    Thank in advance ! :)
     
  33. derek25888

    derek25888

    Joined:
    Apr 23, 2018
    Posts:
    5
  34. Wunder-Waffe

    Wunder-Waffe

    Joined:
    Apr 11, 2018
    Posts:
    2
    Working with unity 2017.4. I have a problem with dissapearing asteroid and boundary though I it worked at start. There must be something wrong with Destroy by boundary script. I have tried out all solutions i could found in the forum but can't get it work. Even using the done scripts doesn't work and the additional documents have no solution. Can someone please point me into the right direction since I lost a few days and lots of nerves trying to find the solution. Thanks!

    EDIT: It took me two days to figure out that one of the other scripts was messed up and only possible explanation is that I closed Unity before I saved that script in Visual Studio so the problematic script didn't get saved properly. So lesson learned the hard way I guess :)
     
    Last edited: May 11, 2018
  35. Psalm_7_11

    Psalm_7_11

    Joined:
    May 12, 2018
    Posts:
    3
    Hi, I have a bizarre problem with my code. My player will not move, and my suspicion is that Unity is not recognizing or reacting to the term "Vector3". My reasoning is that Vector3 is not highlighted in any way in my code, and the player won't even move when I use the premade version of the PlayerMovement script. However, I'm not a C# expert, so this may not be the problem at all. The strange part is that Unity isn't pitching a fit or throwing an error, and I can enter play mode. I'm working in Unity 5.6. Here is a screenshot of my code. CodeShot.PNG
    Thanks!
     
  36. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Confirm that "speed" has a positive non zero value. If it is not set (or zero) then
    movement * speed
    will be zero.

    You could, temporarily, enter the following code between lines 22 and 23:
    speed=2.0f;
    to confirm if this is the problem.

    Also, check unity inspector itself to make sure you do have a value in the "speed" slot
     
  37. Astray-BI-

    Astray-BI-

    Joined:
    May 12, 2018
    Posts:
    1
    Thanks for your tutorial.

    I have noticed a problem in the tutorial that might caused by a change in system.

    As I noticed in the tutorial, the explosion game object is instantiated directly in the scene( without being anyone's child ).
    But in the version that I am using, which is 2018.1.0f2, the explosion game object will be instantiated as a child of asteroid game object after using instantiate function. Then the explosion game object will be destroyed with the death of asteroid game object without showing any VFX.

    I had to add the code below to avoid that problem.

    Code (CSharp):
    1. GameObject explosionIns = Instantiate(explosion, transform);
    2. explosionIns.transform.parent = null;
    3. Destroy(explosionIns, explosion.GetComponent<ParticleSystem>().main.duration);
    If I am wrong or there is any way better to avoid that problem, I will be appreciated to know.
     
  38. Wunder-Waffe

    Wunder-Waffe

    Joined:
    Apr 11, 2018
    Posts:
    2
    Using ver. 2017.4.0f1 In lesson 12 - Spawning waves everything works for me except asteroids are spawning way less frequent like the ones in the lesson. For example when game starts in the lesson there are several asteroids spawning while in my game they spawn one by one by one. I have been experimenting with spawnWait even setting it down/up to 0.001 but nothing much changes. Can someone please tell me how to spawn asteroids within a single spawn/hazardCount faster.
     
  39. Psalm_7_11

    Psalm_7_11

    Joined:
    May 12, 2018
    Posts:
    3
    Thank you for your prompt reply! Actually, that was my first step when I encountered the problem, and it doesn't seem to work with the Done_PlayerController script either. I guess I should have mentioned that in my first post. However, just to be sure, I tried your advice and there was no change.
     
  40. TheDarthFather

    TheDarthFather

    Joined:
    Feb 12, 2018
    Posts:
    3
    Hello,
    I am trying to make the Enemy explosions inherit the speed of the Enemies.
    Based on the short explanation from the video, I attached a RidgidBody to the explosion_asteroid VFX and changed the code as below. However, even if the velocity is changing in de debug (-5 on Z), the explosions seem unnafected.

    I would appreciate any hint .. what am I missing !?
    Thank you!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DestroyByContact : MonoBehaviour {
    6.     public GameObject explosion;
    7.     public GameObject playerExplosion;
    8.     public int scoreValue;
    9.     private GameController gameController;
    10.     private Rigidbody rbExplosion;
    11.     private Rigidbody rb;
    12.  
    13.     void Start ()
    14.     {
    15.         scoreValue = 10;
    16.         rb = GetComponent<Rigidbody>();
    17.  
    18.         GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
    19.         if (gameControllerObject != null)
    20.         {
    21.             gameController = gameControllerObject.GetComponent <GameController> ();
    22.         }
    23.         if (gameControllerObject == null)
    24.         {
    25.             Debug.Log ("No Gamre Controller");
    26.         }
    27.  
    28.     }
    29.  
    30.     void OnTriggerEnter (Collider other)
    31.     {
    32.         if (other.tag =="Boundry" || other.CompareTag("Enemy"))
    33.             {
    34.                 return;
    35.             }
    36.  
    37.         if (explosion != null) {
    38.             Instantiate (explosion, transform.position, transform.rotation);
    39.             rbExplosion = explosion.GetComponent<Rigidbody>();
    40.             if (rbExplosion != null)
    41.             {
    42.                 rbExplosion.velocity = rb.velocity;
    43.                 //rbExplosion.angularVelocity = rb.angularVelocity;
    44.             }
    45.             //Debug.Log ("Exp vel: "+rbExplosion.velocity);
    46.  
    47.         }
    48.  
    49.         if (other.tag == "Player") {
    50.             Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
    51.             gameController.GameOver ();
    52.         }
    53.  
    54.         gameController.AddScore (scoreValue);
    55.         Destroy (gameObject);
    56.         Destroy (other.gameObject);
    57.  
    58.     }
    59.  
    60. }
    61.  
     
    Last edited: May 14, 2018
  41. Psalm_7_11

    Psalm_7_11

    Joined:
    May 12, 2018
    Posts:
    3
    Try changing "Horizontal" and "Vertical" to "Mouse X" and "Mouse Y" respectively. I was having the same problem and this fixed it. The issue is that the tutorial gave axis names that were linked to the wrong user input. Try going to Edit>Project Settings>Input and checking if the axis names for mouse movement (as opposed to some other form of input, such as a button press) match the ones in your code. If not, that may be your problem. Hope this helps!
     
  42. Fallstop

    Fallstop

    Joined:
    Dec 7, 2017
    Posts:
    1
    Hey, I am having trouble on the tutorial Counting points (3, 2) and I am getting the error when I'm getting the DestroyByContact script to contact the GameController script when an asteroid is destroyed:

    NullReferenceException: Object reference not set to an instance of an object
    DestoryByContacte.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Assets/Scripts/DestoryByContacte.cs:42)

    Please ignore all of the messy code

    DestroyByContact script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4.  
    5. public class DestoryByContacte : MonoBehaviour
    6. {
    7.     public GameObject explosion;
    8.     public GameObject playerExplosion;
    9.     public int scoreValue;
    10.     private GameController gameController;
    11.     void start ()
    12.     {
    13.         GameObject gameControllerObject = GameObject.FindWithTag("GameController");
    14.         if (gameControllerObject != null)
    15.         {
    16.             gameController = gameControllerObject.GetComponent <GameController> ();
    17.         }
    18.         if (gameController == null)
    19.         {
    20.             Debug.Log("Cannot find 'GameController' script");
    21.         }
    22.     }
    23.     void OnTriggerEnter(Collider other)
    24.     {
    25.        
    26.         if (other.tag == "Boundary")
    27.         {
    28.             return;
    29.         }
    30.        
    31.         Instantiate(explosion, transform.position, transform.rotation);
    32.         if (other.tag == "Player")
    33.         {
    34.             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
    35.             //gameController.GameOver();
    36.         }
    37.    
    38.         gameController.AddScore (scoreValue);
    39.        
    40.         Destroy(gameObject);
    41.         Debug.Log(other.tag);
    42.     }
    43. }
    GameController script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class GameController : MonoBehaviour
    6. {
    7.     public GameObject hazard;
    8.     public Text scoreText;
    9.     public Vector3 spawnValues;
    10.     public int hazardCount;
    11.     public float spawnWait;
    12.     public float startWait;
    13.     public float waveWait;
    14.  
    15.     private int score;
    16.  
    17.     void Start()
    18.     {
    19.         score = 0;
    20.         UpdateScore();
    21.         StartCoroutine(SpawnWaves());
    22.     }
    23.  
    24.     IEnumerator SpawnWaves()
    25.     {
    26.        
    27.         yield return new WaitForSeconds(startWait);
    28.        
    29.         while (true)
    30.         {
    31.            
    32.             for (int i = 0; i < hazardCount; i++)
    33.             {
    34.                 Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), spawnValues.y, spawnValues.z);
    35.                 Quaternion spawnRotation = Quaternion.identity;
    36.                 Instantiate(hazard, spawnPosition, spawnRotation);
    37.                
    38.                 yield return new WaitForSeconds(spawnWait);
    39.             }
    40.             yield return new WaitForSeconds(waveWait);
    41.         }
    42.     }
    43. public void AddScore (int newScoreValue)
    44.     {
    45.         score += newScoreValue;
    46.         UpdateScore ();
    47.     }
    48.     void UpdateScore()
    49.     {
    50.         scoreText.text = "Score: " + score;
    51.     }
    52. }
    53.  

    Other Infomation:
    Only happens when I shoot an asteroid
     
  43. Beliywolk

    Beliywolk

    Joined:
    May 14, 2018
    Posts:
    1
    Hi, everyone.
    I have some strange bug in the DestroyByContact script.

    I have updated it slightly to my taste.
    I've made it to check if "Enemy" collides with "BoltPlayer" (new tag for Bolt Player) and only in this case add score.

    The problem is this code works great inside Unity, but not in WEB. When I build it and launch it in WEB the game itself works just fine, but it doesn't count the score at all.

    I've tried this code in different ways and the result is always the same. It works inside Unity, doesn't work in WEB.
    If I use just
    gameController.AddScore (scoreValue);
    without my IF statement it works well in WEB and in Unity.

    Maybe you know what can cause such a different behavior of the code?

    Code (CSharp):
    1. if (gameObject.CompareTag ("Enemy") && other.CompareTag ("BoltPlayer")) {
    2.             gameController.AddScore (scoreValue);
    3.         }
     
  44. szefff

    szefff

    Joined:
    Mar 20, 2018
    Posts:
    1
    Hi,
    How can I change the background color when shooting down the enemy? What and where would I have to add?
     
  45. smokinimages

    smokinimages

    Joined:
    May 13, 2018
    Posts:
    1
    For anyone having issues with the asteroid explosion clones not being removed I added the following script to the explosion_asteroid Prefab. It simply checks if the explosion game object is older than 2 seconds and if so destroys it. Should help keep things tidy and stop errors due to many objects being created.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class destroyExplosion : MonoBehaviour {
    6.     public float startTime;
    7.     // Use this for initialization
    8.     void Start () {
    9.         startTime = Time.time;
    10.     }
    11.    
    12.     // Update is called once per frame
    13.     void Update () {
    14.         if (Time.time-startTime > 2) {
    15.                      Destroy(gameObject);
    16.                }
    17.     }
    18. }
    19.  
     
  46. davedouggreen

    davedouggreen

    Joined:
    Nov 15, 2017
    Posts:
    1
    Apologies for hijacking, but im also having the same problem in that my laser bolts do not move when dragging them into the hierarchy, and i noticed you replied that we are to make sure our mesh collider is convex, my question then is, aren't we instructed to remove the mesh collider altogether and replace it with a capsule collider?
     
  47. Roo_027

    Roo_027

    Joined:
    May 29, 2018
    Posts:
    1
    I too have a small issue with my bolt. When I drag and drop it onto the scene, it appears and then drops out of view. It is still there though because I can see the Y and Z values in the Transform section of the Inspector increasing/decreasing.

    My gravity on the Rigidbody is indeed ticked off. The speed is set to 20. Not sure what is wrong? I have included the code up until the adding of the "Shooting" features which is one video ahead from where I got stuck as I thought in future videos I would figure the answer out.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. [System.Serializable]      //This ensures that the class of boundary becomes serialized and visible in the UNity editor
    6. public class Boundary       //creating a separate class for the boundary only
    7. {
    8.     public float xMin, xMax, zMin, zMax;
    9. }
    10.  
    11.  
    12. public class PlayerController : MonoBehaviour {
    13.     private Rigidbody _rb;
    14.     public float speed;
    15.     public Boundary boundary;
    16.     public float tilt;
    17.  
    18.     public GameObject shot;
    19.     public Transform shotSpawn;
    20.     public float fireRate;
    21.  
    22.     private float nextFire;
    23.  
    24.     void Update ()
    25.     {
    26.         if (Input.GetButton("Fire1") && Time.time > nextFire) {
    27.             nextFire = Time.time + fireRate;
    28.             // GameObject clone =
    29.             Instantiate(shot, shotSpawn.position, shotSpawn.rotation); // as GameObject;
    30.         }
    31.     }
    32.  
    33.     private void FixedUpdate()
    34.     {
    35.         float moveHorizontal = Input.GetAxis("Horizontal");     //This grabs the input from the player
    36.         float moveVertical = Input.GetAxis("Vertical");
    37.  
    38.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    39.         _rb = GetComponent<Rigidbody>();
    40.         _rb.velocity = movement * speed;
    41.  
    42.         _rb.position = new Vector3(Mathf.Clamp(_rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(_rb.position.z, boundary.zMin, boundary.zMax));
    43.         _rb.rotation = Quaternion.Euler(0.0f, 0.0f, _rb.velocity.x * -tilt);
    44.     }
    45. }
     
  48. quilladin

    quilladin

    Joined:
    May 9, 2018
    Posts:
    1
    Hey everyone,
    I have the ship shooting automatically from the moment the game starts and would like to reduce the fire rate from being non-stop every frame. Does anyone know how to do this?
     
  49. Nobb3

    Nobb3

    Joined:
    May 24, 2018
    Posts:
    1
    I am in the Extending space shooter part of the tutorial and am having troubles with the enemy ship bolts, when i enter play mode the enemy bolts shoots upwards instead of at the player. I already rotated the shot spawn 180° on the y axis, and I'm not sure what I did wrong?
     
  50. Ahsanshaaf761

    Ahsanshaaf761

    Joined:
    Jun 10, 2018
    Posts:
    1
    stuck on boundary .....i have done everything but its not show any boundry instead it goes to bolt