- Home /
Problem with Coding for Brick Shooter Tutorial
Hello, all. I was going through the Brick Shooter tutorial and entered the code to where it appeared the same as on the video, but when I tried to play it and see if it worked, Unity told me that all compiler errors must be fixed first. I double-clicked the red stop sign, and it opened MonoDevelop, with the indicator on the first line of my text informing me that it "expected EOF, found '}'."
Other times in the past it would tell me to add on a semicolon to the first line when I already had one, and I have not been able to get Mono to work for some reason with scripts that I write. In case it is of any assistance, I have copied and pasted exactly (The first two lines lack the extra space between them, though) what was in the script:
using UnityEngine;
using System.Collections;
public class shooter : MonoBehaviour {
public Rigidbody projectile;
public Transform shotPos;
public float shotForce = 1000f;
public float moveSpeed = 10f;
function Update () {
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(new Vector3(h, v, 0f));
if(input.GetButtonUp("Fire1"))
{
Rigidbody shot = (Instantiate(projectile, shotPos.position, shotPos.rotation) as Rigidbody;
shot.Addforce(shotPos.forward * shotForce);
}
}
}
I am uncertain of what is wrong. Any help on this matter would be very much appreciated.
Answer by robertbu · Aug 16, 2013 at 08:30 PM
You are missing a closing ')':
Rigidbody shot = (Instantiate(projectile, shotPos.position, shotPos.rotation)) as Rigidbody;
Also on line 6, 'function' should be 'void'. 'function' is Javascript/Unityscript.
Answer by IgorAherne · Aug 16, 2013 at 08:27 PM
try making this:
Rigidbody shot = (Instantiate(projectile, shotPos.position, shotPos.rotation) as Rigidbody;
into this
Rigidbody shot = (Rigidbody)Instantiate(projectile, shotPos.position, shotPos.rotation);
also, instead of
transform.Translate(new Vector3(h, v, 0f));
try transform.position = new Vector3(h,v,0f);
and, yes, you are missing the ) bracket, as the guy below me noticed
I tried all of these changes, but it is still telling me to "insert a semicolon at the end", followed by the blinking indicator for the first line. Am I still missing something?
using UnityEngine; using System.Collections;
public class shooter : $$anonymous$$onoBehaviour {
public Rigidbody projectile;
public Transform shotPos;
public float shotForce = 1000f;
public float moveSpeed = 10f;
void Update () {
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.position = new Vector3(h, v, 0f);
if(input.GetButtonUp("Fire1"))
{
Rigidbody shot = (Rigidbody)Instantiate(projectile, shotPos.position, shotPos.rotation);
shot.Addforce(shotPos.forward * shotForce);
}
}
}
Answer by daufuzz · Dec 12, 2013 at 11:56 PM
Were you ever able to solve this issue? I've run into the same issue..