Space Shooter Tutorial Q&A [ARCHIVED]

I decided to spend a weekend and go through this tutorial package and see what it had to offer. I am glad that I did.

The tutorial itself was well paced and explained what the code is doing quite well. The minor issues that I had with code generally dealt with me missing a minor step (such as turning the Capsule Collider off for the asteroids…) but were resolved easily before I moved onto the next section.

This tutorial, as it stands, is called Chapter 1 and there obviously are some things that are missing from the ‘published final project’ than what I see in the provided “Done Demo” game. Such as a scrolling background, enemy ships, etc.

I’m looking forward to seeing the next chapter/installment of this tutorial series to be posted soon. I’m picking apart the scripts in the Done folder to see how they work, but I tend to pick things up a little faster with the video tutorials for some reason. Any word on when we might see Chapter 2?

Regardless, this project helped me understand C# better. Having done so much coding in Javascript I found the general layout for C# to be somewhat… alien. This project helped overcome that hurdle and I am looking forward to more from the Unity Team.

Joseph.

Just putting this here for anyone else that might get stuck. I’m using Unity 4.3.2f and had an issue or two during the ‘Shooting Shots’ part of the tutorial.

Where it says in the script:

I was getting errors about both position and rotation, and subsequent errors relating to the same. 4 in total.

If you simply connect these to transform, it works fine. If you’re having this issue, change to;

Thanks for a great tutorial!
:slight_smile:

Hi, I’m having a problem with the Space Shooter tutorial and would be grateful for some help…

In Chapter 10 (‘Creating Hazards’), there is a moment when the asteroid disappears and the tutorial goes on to explain about tagging.

Thing is, my asteroid doesn’t disappear - and if I go on to follow the tagging section, there is no collision detection between the ship/shot and asteroid. They just go through each other.

I’m thinking it might be something to do with the boundary settings?

Could anyone suggest something? Thanks…

–Code I’m using for DestroyByContact:

using UnityEngine;
using System.Collections;

public class DestroyByContact : MonoBehaviour {

	void OnTriggerEnter(Collider other) {
		Destroy(other.gameObject);
		Destroy (gameObject);
	}
}

In the JScript example for Shooing Shots in the Update function there is a call to audio.Play(); This causes issues since there is no audio associated with the script yet. This should be removed so others don’t have an issue with it.

Hey Adam,

I just sailed through Chapter One. Great job!

Any news on when Chapter Two will be ready? My game needs some parallax.

-Rob.

Parsing Error means that there is an error in the script somewhere and the compiler cannot parse it correctly.

You will need to go back through the tutorial and double check your code, or compare it with the “done” code in the “done” directory.

That being said, I do not recognise “StarfighterController”. Did you make your own name?

Lastly, you can post your code, and we can take a look at it and see where it went off the rails.

1 Like

We will do additional videos when we can fit them into our schedule.

Glad you liked them!

This is probably due to a mistake in your declaration of the variable.

Rewatch this section of the video, as we cover this specifically.

If you declare: public GameObject shotSpawn;

… then you will need to access this with shotSpawn.transform.rotation;

If, however, you declare public Transform shotSpawn;

… then you only need shotSpawn.rotation, as this is of the type transform already.

I’ll take a look! This could be due to the way these scripts are built upon each other, one lesson at a time.

Thanks for the feedback. We will make additional videos as our schedule allows.

1 Like

(I added code tags to your post for better reading…)

My first suggestion would be to rewatch the video and/or compare your code to the final “done” version in the “done” folder.

If this doesn’t solve your problem, post again here, and we’ll do what we can.

There is a problem downloading the assets. When I click on open in Unity, it just says “please wait”. I tried with IE Firefox on Win 8.1

I recommend that you download the material directly into Unity from Unity.

To download this project directly into Unity, it’s best that you have Unity open and you go to the asset store using Window / Asset Store or use the hot key of + 9 (on mac) or + 9 (on win) to open the asset store in the editor and search for Space Shooter. Use the “download” button to download the assets directly into your project.

You can alternatively follow this link in a browser and select “Open in Unity”; but this doesn’t seem to be working for you.

If, for some reason, you can’t get the web link and “open in Unity” to work, and you think it’s a bug, you can report a bug by using the bug reporting feature in Unity by navigating to “Help / Report a Bug”.

Hi, I’m having a problem with the Space Shooter tutorial and would be grateful for some help.

In Chapter 9 Boundary, after placing the script Boundary, the shot becomes invisible, it follows cloning.
In the video note that appears in the script folder, TESTER.cs not know if that has something to do.

First create the cube, change the dimensions as in the video, I put the trigger option, then create the script, add it to the script folder, then copy the script and add, delete and render mesh Mesh filter cube .

the shot still cloning, but the shot if it becomes invisible when he touches the Box Clollider.

I watched the video many times, but I dont know what is wrong.

I completed all the chapters and until 8 correctly.

If anyone can help me, would be helpful.
Thank you.

Checo:

Are your shots being destroyed? Or are they in fact “invisible” and not being rendered?

I’m not sure I understand “it follows cloning”…

The “Tester.cs” you are talking about… I believe this was an oversight during recording and it should have been removed. This script is not attached to a GameObject, so it does not affect the scene. If we re-render this video, it will be removed.

The important points are the code being written in MonoDevelop and the steps being performed in the Unity editor.

Have you re-watched the video and checked your steps? Have you compared your finished scene with the “done” scene in the “done” folder?

Some guesses, as I don’t have a lot of information:

  • Find out whether the shot is not being rendered or is being destroyed.
  • Check to see if for some reason you are using the code for “OnTriggerExit” NOT “OnTriggerEnter”?

If you still have issues, please post the details here and we’ll try to get you back on track.

Hi, Thanks for the reply Adam, I just checked and correct the problem, excellent tutorial.
Thank you very much.

I’m having a similar problem to Checo. I can get the ship to fire once, and then get the error message “MissingReferenceException: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.” I’ve compared my code to the done code and aside from minor formatting issues cannot find what’s different.

The missing reference exception is best described by the accompanying details: “The object of type ‘GameObject’ has been destroyed but you are still trying to access it.”

This means you are referencing an object and then destroying it.

So - check the reference. This will probably not be a code issue, but rather an assembly issue. Check your scene to the done scene, rather than your code to the done code.

You could be calling an instantiate, like Instantiate (shot, spawn.position, spawn.rotation); and the “shot” game object is missing when you call it, as it is referenced with public GameObject shot;

I’m guessing here… Could you have used a “shot” GameObject Instance, rather than the “shot” GameObject prefab? You will want to use your shot prefab in your project view not a shot instance in your scene.

If this is not the issue (as I am guessing), can you tell us more about your set up?

Compare the scenes and look for clues, but if your still stuck, post a screen shot of your project view setup and we’ll get to the bottom of it.

I’m having an issue during this tutorial that I’m eager to learn how to fix. In the Spawning Waves part of the tutorial, I’m following along and creating the first part of the GameController script at about 3:00-3:30.

The video shows all the asteroids moving straight down the screen (other than the ones that instantly collide with each other and explode), but mine all seem to go off in random directions, including on the Y-axis. A single asteroid that I introduce to the scene to test works just fine, so I figure there is something wrong that I am missing. My code for GameController at this point is as follows:

using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour
{
	public GameObject hazard;
	public Vector3 spawnValues;
	public int hazardCount;
	
	void Start ()
	{
		SpawnWaves ();
	}
	
	void SpawnWaves ()
	{
		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);
		}
	}
}

I’m fairly certain I have duplicated the code exactly up to that point on the video. However, I also tried copying the entire GameController example code at the bottom of the page with the video, and the asteroids still move in random directions. I’ve also checked the ‘Done’ scene, and those work as they’re intended. I’m sure I missed something, but I’m not sure where to begin looking.

edit - To clarify, the asteroids that are instantiated do always travel ‘downward’ in relation to the Z-axis. My problem is that they also randomly travel left or right at an angle on the X-axis, and ‘toward’ or ‘away’ from the camera on the Y-axis.

edit 2 - After further poking and prodding, and a bit of experimentation, I realized what was making my asteroids move randomly. Instead of exploding when being instantiated on top of each other (since they were all spawning at the same time), they were ‘bouncing’ off of one another. I’m still not sure why, I’m fairly certain I followed the tutorial closely. But, continuing with the video, and having them spawn one asteroid every 1/2 seconds fixes the problem, and I get the desired behavior.

Hi Adam,

Finished your tutorial and loved it. I was able to get everything going and even added some tweaks of my own. EXCELLENT video. It is very appreciated.