This is the official thread for discussion, issues and Q&A for the Space Shooter tutorial.
Please use this thread if you have any questions, issues or feedback on this project.
Space Shooter is a learning project on our Learn Site:
Expand your knowledge and experience of working with Unity by creating a simple top down arcade style shooter. Using basic assets provided by Unity Technologies, built-in components and writing simple custom code, understand how to work with imported Mesh Models, Audio, Textures and Materials while practicing more complicated Scripting principles.
Common Upgrade Issues (please see the upgrade guide for details):
Unity 5: When using the mesh collider and adding the simplified mesh, the mesh collider must be “convex” when using Unity 5. Please check “convex” on the mesh collider component.
Unity 5: Ambient light is now set differently. Please delete the default skybox from the Lighting panel and make sure it is set to “None”.
Unity 5: Common components are no longer cached and there are no “helper references” access them.
Common Misunderstandings:
My GUIText is not visible on the screen
Check to make sure that the Transform Position x and y values are between 0 and 1.
In the Transform Position x value is either of the extremes of 0 or 1, make sure that the alignment is not pushing the text off of the screen.
Check that any “Parent” GameObject (like a holder game object) is set to “origin”, or (0,0,0) in its Transform Position.
My Bolt Object is laggy when fired
Make sure you have the Rigidbody component set according to the steps in the video and that you only have one Rigidbody in the GameObject family (eg: You don’t have one Rigidbody on the root and one on the VFX Quad).
I am having a problem were a little speaker and a line are being shown on the game screen underneath the player ship. I got the text to work by importing UnityEngine.UI then changing scoreText variable from GUIText to Text. And using the canvas text object.
I did have the sound gizmo and the canvas gizmo turned on though I don’t remember turning them on. Is this the default action when you add a canvas or sound object? Thanks for your reply.
I’m sorry but after testing I found the sound gizmo was still there. The line disappeared when I turned the canvas gizmo off. I went to the scene view and highlighted it and it was the player controller script that placed the sound gizmo in the game when played as there was a audio source component attached to it. I set the player controller script to 17 on the zed axis to move it out of the scene and that worked. This happened when I created the canvas text object and dragged the Text object onto the player controller script.
stuck again, I am working on the part to add a score to the game. After following the instructions I am getting 19 errors. I went through and found a few typo’s on my end, but that seem to make it worse. I even copy pasted from website over. Not sure what I am doing wrong now.
using UnityEngine;
using System.Collections;
public class Destroy_by_Contact : MonoBehaviour
{
public GameObject explosion;
public GameObject playerexplosion;
public int scoreValue;
private 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)
{
// as long as boundary is tagged it will not destroy new objects in area until reaches proper code
// remember to create a tag in Unity called Boundary set it and save scene before testing.
if (other.tag == "Boundary")
{
return;
}
Instantiate (explosion, transform.position, transform.rotation);
if (other.tag == "Player")
{
Instantiate (playerexplosion, other.transform.position, other.transform.rotation);
}
gameController.AddScore (scoreValue);
Destroy (other.gameObject);
Destroy (gameObject);
}
}
I am having a problem with creating the bolts. My code for the Mover script is a mirror image of the script in the done folder. I follow everything in the tutorial but when I remove the bolt from the hierarchy and instantiate it while running the game like in the tutorial, it doesn’t move but just sits static on the view. Any idea what it could be?
I will do that now. Also, if it helps, I am receiving the error message ‘‘Non-convex MeshColliders with non-Kinematic rigidbodies are no longer supported in Unity 5’’.
Edit: Of Course writing __S__tart() with a capital S would help referencing the rigidbody -.- . I’ll leave this post here for now… but the problem should be solved.
Hello Adam,
I took my first steps into unity by following your roll a ball tutorial. I was very happy to find that I did not run into any errors I could not solve myself.
Unfortunately I’ve not been so lucky with the Space Shooter tutorial… I got stuck on the basic movement script.
I referenced the rigidbody in the start() after creating a private variable for it. However, my ship is unable to move, and the console is telling me:
NullReferenceException: Object reference not set to an instance of an object
PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:20)
my code is below, I checked it with the basic movement script used for the roll a ball tutorial, which worked fine, but could not find any differences.
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
private Rigidbody rig;
void start()
{
rig = GetComponent<Rigidbody> ();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rig.velocity = movement;
}
}
The console tells me to look at line 20, however I can not comprehend what is wrong with this line, or earlier declarations of the rigidbody in the code.
This is covered in the original post as a known issue. It’s a change with the way the physics system works in Unity 5. You need to make sure the mesh collider is convex. See the original post for more detail.
currently going through the space shooter tutorial, and everything has gone okay, until actually firing the bloody shots! lol
they fire fine when actually dragging the bolt icon onto the shot spawn bit, but when actually controlling and using left ctrl to fire (as instructed in the input manager) the ship flies fine, but nothing shoots out?
code seems fine, but my ships lacking umph!
cheers in advance!
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
private Rigidbody Rigidbody;
public float speed;
public float tilt;
public Boundary boundary;
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;
// GameObject clone =
Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
}
}
void Start (){
Rigidbody = GetComponent<Rigidbody> ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Rigidbody.velocity = Random.insideUnitSphere;
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);
}
}
I’m not sure if this is the right place to be asking this… but… I was doing a similar space shooter project and managed to add player controls for the keyboard. I wanted to see if there was a way to convert the controls so it would be able to be played across ios devices through some sort of a joystick and shoot button instead of W, A, S, D and space to shoot. I really wanted to finish this project, and so far it’s the last thing I have to complete it. I’m pretty new to this and have been looking all over the forums for a good explanation for months now… most of them I was able to try… with no luck though… this was my last hope.
im not sure but there might be some minor alterations required to the code for unity 5, but im sure that Adam will advise.
the theory and basics are all there tho.
Line 11: you have “private Rigidbody Rigidbody;” because of the capitalisation, you don’t have “an access modifier, a type and a name” you have “an access modifier, a type and a type”. You need to use another name other than the name of the type as Rigidbody. A common convention is to use rb.
This is true of line 34 as well. And 40, 42, 44 etc.
Are you getting any errors?
And…
What’s line 40 doing in there? That’s a redundant line that seems related yo the hazards!
Thank you so much for referring me to this tutorial OboShape, I’ll try and check it out as soon as I can and hopefully I’ll be able to get my game working…