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 nichos1 · May 11, 2013 at 08:10 PM · movementshootingthird-person

Broken scripts(need help fixing)

Hi, I have some scripts here I got from a website, and they are broken by syntax errors. I was wondering if anyone would help me fix them. Whenever I add a script to my player, the script never shows the local variables for the movement speed. Could anyone help me, I'm new.

MOVEMENT....

 var speed : float = 6.0;
 var jumpSpeed : float = 8.0;
 var gravity : float = 20.0;
 
 private var moveDirection : Vector3 = Vector3.zero;
 
 function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirecti­on); moveDirection *= speed; if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; } } // Apply gravity moveDirection.y -= gravity * Time.deltaTime; // Move the controller controller.Move(moveDirection * Time.deltaTime);
 }

SHOOTING

 var Bullet:Transform;
 
 var ShootingForce = 100.0;
 
 
 function Update () {
 if(Input.GetButtonDown("fire"))
 {
 var fire = Instantiate(Bullet, transform.position, Quaternion.identity);
 fire.rigidbody.AddForce(transform.right * ShootingForce);
 }
 }

Comment
Add comment · Show 2
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 DaveA · May 11, 2013 at 08:11 PM 0
Share

You won't see the variables until the script compiles without errors. You are unlikely to get an answer unless you format your code. Edit your post, select the code, hit the 101/010 button, save.

avatar image Daphoeno · May 11, 2013 at 09:50 PM 0
Share

In the second script at line 9 I don't believe you need the var when na$$anonymous$$g an action like you do there.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by seejayjames · May 11, 2013 at 11:07 PM

The first script needs reformatting...the long line that's in red is mostly commented out, and many parts are needed to NOT be commented. Find the script again and get it formatted right, that's the source of most of your errors. I tried a reformat below to save you the hassle, but it's hugely important that you learn how the brackets etc. work, otherwise you'll never get far with scripting...takes time but is worth it!

Not sure if naming the bullet "fire" is a good idea, because that's the same as the GetButtonDown. Maybe it's not a problem though.

And you do need "var" in the "var fire" line, otherwise you'll get an error...without it, unity assumes you've created that variable already.

Comment
Add comment · Show 3 · 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 seejayjames · May 11, 2013 at 11:13 PM 0
Share

var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() {

 var controller : CharacterController = GetComponent(CharacterController); 

 if (controller.isGrounded) { 
     // We are grounded, so recalculate move direction directly from axes 

     moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

     moveDirection = transform.TransformDirection(moveDirecti­on); 

     moveDirection *= speed; 

     if (Input.GetButton ("Jump")) { 
         moveDirection.y = jumpSpeed; 
     } 
 } 

 // Apply gravity
 moveDirection.y -= gravity * Time.deltaTime; 

 // $$anonymous$$ove the controller
 controller.$$anonymous$$ove(moveDirection * Time.deltaTime);

}

avatar image nichos1 · May 12, 2013 at 12:00 AM 0
Share

it says there is a unexpected char 0xAD

avatar image seejayjames · May 12, 2013 at 01:24 AM 0
Share

might be a non-printing character in the script from when you copied. you should re-enter the script fresh, by hand. it's tedious but will be worth the practice for formatting, getting used to brackets, syntax, etc.

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

Shooting speed help! 1 Answer

How to store gameobjects with specific scripts in a list ? 1 Answer

New Level (Scene) after Enemies are gone 1 Answer

How to smoothly rotate camera around an object with touch 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