Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Astro-King · Aug 16, 2013 at 08:25 PM · programming

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Astro-King · Aug 18, 2013 at 06:33 PM 0
Share

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

}

avatar image
0

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..

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Working Reference Still Throwing Null Reference Error 0 Answers

What is a good unityscript writing program? 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

A node in a childnode? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges