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 GraviterX · Dec 01, 2013 at 05:19 AM · camera

Script Issue

Hi all! I've been trying to change my FOV for my main camera when the sprinting function is true, but I've been getting errors. I'm new to coding so if anyone can give me any advice to correct these errors that would be awesome! Here is the script and the list of errors: static var bobbingSpeed; static var bobbingAmount; static var playerStamina = 600;

 static var audioStepLength: float = 0.5;
 static var stepSound = 0;
 
 var walkSpeed: float = 7; // regular speed
 var sneakSpeed: float = 3; // sneaking speed
 var runSpeed: float = 20; // running speed
 
 var walkStep: float = 0.5;
 var sneakStep: float = 1;
 var runStep: float = 0.45;
 
 private var isRunning: boolean = false;
 
 private var chMotor: CharacterMotor;
 private var tr: Transform;
 private var dist: float; // distance to ground
 
 function Start(){
     chMotor = GetComponent(CharacterMotor);
     tr = transform;
     var ch:CharacterController = GetComponent(CharacterController);
     dist = ch.height/2; // calculate distance to ground
 }
 
 function Update(){
     if(chMotor.grounded){
         bobbingSpeed = 0.20;
         bobbingAmount = 0.3;
     } else {
         bobbingSpeed = 0;
         bobbingAmount = 0;
     }
     
     var vScale = 1.0;
     var speed = walkSpeed;
     audioStepLength = walkStep;
     stepSound = 2;
  
  if (!isRunning){
  if (playerStamina < 250){
    playerStamina = playerStamina+2;
  }
  } else if (isRunning){
  if (playerStamina >= 0){
    playerStamina = playerStamina-3;
  }
  }
  
  isRunning = false;
  
     if (Input.GetKey("left shift") && chMotor.grounded){ // press LShift to run
  if (playerStamina >= 3){
    isRunning = true;
    
    audioStepLength = runStep;
    stepSound = 0;
    
    speed = runSpeed;
       bobbingSpeed = 0.30;
       bobbingAmount = 0.3;
      } else {
    isRunning = false;
      }
     }
  
     if (Input.GetKey("c")){ // press C to sneak
         speed = sneakSpeed;
         bobbingSpeed = 0.15;
         bobbingAmount = 0.1;
         
         audioStepLength = sneakStep;
         stepSound = 1;
     }
     
     chMotor.movement.maxForwardSpeed = speed; // set max speed
     var ultScale = tr.localScale.y; // crouch/stand up smoothly 
     tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
     tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position
 }
 
 function Update(){
     if(isRunning = true){
         {
             SetFOV(70.0)
         }
     }
     
 function Update(){
     if(isRunning = false){
         {
             SetFOV(60.0);
         }
     }
 }
 }

 Errors: 93,24 unexpected token: false. 93,22 expecting ( found =. 92, 18 ; expected, inset semicolon. 92,10 expecting ( found Update. 88,37 ; expected, inset semicolon. 86,24 unexpected token: true. 86,22 expecting ) found =.
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tomer-Barkan · Dec 01, 2013 at 05:22 AM

Before starting with Unity, I recommend starting with some basic C# tutorials... You'll need a better basic knowledge of programming and C# to be able to script well with unity.

But anyway, one thing I see here is that you're using if (x = y). In C#, if you want a true/false result whether two variables are equal, you use the double equals sign (`==`), so your ifs need to change to if (x == y).

I saw this in line 89 and line 82 of the code as pasted in your question.

Some C# tutorials:

http://msdn.microsoft.com/en-us/library/aa288436(v=vs.71).aspx

http://www.tutorialspoint.com/csharp/

Comment
Add comment · Show 10 · 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 GraviterX · Dec 01, 2013 at 05:49 AM 0
Share

This doesn't really help the errors, but thank you for the links and they will come in handy.

avatar image Tomer-Barkan · Dec 01, 2013 at 09:28 PM 0
Share

Edit your question please with the updated code and error message after fixing the = to ==. It should have fixed it.

avatar image GraviterX · Dec 03, 2013 at 10:43 PM 0
Share

These errors remain: 88,22 ; Expected. Insert semicolon. 92,10 expecting ( found Update. 92,18 ; Expected. Insert semicolon.

avatar image Tomer-Barkan · Dec 04, 2013 at 05:16 AM 0
Share

You really have to learn coding. These are all syntax errors. Just read what they say and which line, and you'll find the error.

For example, the first error refers to a missing ; in :

 SetFOV(70.0)
avatar image GraviterX · Dec 05, 2013 at 08:52 PM 0
Share

Thanks. I do I just started making games all I use to do was make animations in $$anonymous$$icrosoft Powerpoint. I have never seen any coding before.

Show more comments

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

18 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 avatar image

Related Questions

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

FPS Camera moving by my left mouse button 1 Answer

Top down camera 1 Answer

how to switch camera 2 Answers

Minimap Camera Question 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