Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Tom507 · Dec 11, 2017 at 08:56 AM · errorcontext

wierd not existing in current context error caused by 2 lines of code

Hi guys I have the errors

  Assets/Code/FPS_Controller.cs(70,37): error CS0103: The name `moveVert' does not exist in the current context 

and

 Assets/Code/FPS_Controller.cs(70,51): error CS0103: The name `moveHor' does not exist in the current context

but i am not at all referencing these variables anywhere except where they were created witch is fixedUpdate, and even less in Update where theese errors are pointing (but they apeared once i moved the Jump code into Update)


Here is my simple fps conntroller script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FPS_Controller    : MonoBehaviour {
 
     public float Accellaration;
     public float maxSpeed;
     public float JumpHeight;
 
     public float MouseSpeed = 3;
     public GameObject Camera;
     //public GameObject parent;
     public float Zoffset= 0;
 
     private float LookAngleX = 0;
     private float LookAngleY = 0;
 
     private Rigidbody rb;
     private Animator anim;
     private Vector3 movement;
     private Vector2 XYmovement;
     private  float Jump;
 
     // Use this for initialization
     void Start () {
         rb = gameObject.GetComponent<Rigidbody>();
         anim = GetComponent<Animator> ();
     }
 
     void FixedUpdate (){
         float moveVert = Input.GetAxis ("Vertical");
         float moveHor = Input.GetAxis ("Horizontal");
 
         XYmovement = new Vector2 (rb.velocity.x, rb.velocity.z);
 
         if( XYmovement.magnitude > maxSpeed)// clamping speed to max speed
         {
             XYmovement = XYmovement.normalized * maxSpeed;
             rb.velocity = new Vector3 (XYmovement.x, rb.velocity.y, XYmovement.y);
         }
 
         movement = new Vector3 (moveVert, Jump, -moveHor);
         movement = transform.TransformDirection (movement);
 
         rb.AddForce (movement*Accellaration);
 
 
 
         // Taking controller mouse input
         var Xin = Input.GetAxis ("Mouse X");
         var Yin = Input.GetAxis ("Mouse Y");
 
         LookAngleX += Xin * MouseSpeed;
         LookAngleY += Yin * MouseSpeed;
 
         LookAngleY = Mathf.Clamp (LookAngleY, -25f, 89f);
 
         Camera.transform.localEulerAngles = new Vector3(-LookAngleY, Zoffset, 0f);
         transform.eulerAngles = new Vector3(0f, LookAngleX, 0f);
         //transform.eulerAngles = new Vector3(0f, LookAngleX, 0f);
 
         Jump = 0f;
 
     }
     // Update is called once per frame
     void Update () {
         if (Input.GetButtonDown ("Jump")) {
             Jump = JumpHeight;
         }//############################## this is the line in wich both errors ocurr 
     }
 }




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 tcjulian · Dec 11, 2017 at 10:00 AM 0
Share

Have you tried clearing the error console? I just copied this script into Unity and didn't get any errors or warnings. If you have, maybe consider deleting your Library and Temp folders?

avatar image Bonfire-Boy · Dec 11, 2017 at 02:53 PM 0
Share

Agreed. The code shown above does not seem to be the code that is causing that error.

2 Replies

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

Answer by Tom507 · Dec 15, 2017 at 12:21 PM

thanks for your suggestions but it turns out restarting my pc fixed it XD that was a really weird bug...

so it was propably as tcjulian and Bonfire-Boy suggested something that somehow stayed in cash from an earlyer compilation

so thanks again

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 KittenSnipes · Dec 13, 2017 at 12:23 AM

@Tom507

Why dont you try moving these two lines:

 float moveVert = Input.GetAxis ("Vertical");
 float moveHor = Input.GetAxis ("Horizontal");

Move them under the if statement in FixedUpdate. So it should look like this now:

 void FixedUpdate (){         
          XYmovement = new Vector2 (rb.velocity.x, rb.velocity.z);
  
          if( XYmovement.magnitude > maxSpeed)// clamping speed to max speed
          {
              XYmovement = XYmovement.normalized * maxSpeed;
              rb.velocity = new Vector3 (XYmovement.x, rb.velocity.y, XYmovement.y);
          }
          
          float moveVert = Input.GetAxis ("Vertical");
          float moveHor = Input.GetAxis ("Horizontal");
 
          movement = new Vector3 (moveVert, Jump, -moveHor);
          movement = transform.TransformDirection (movement);
  
          rb.AddForce (movement*Accellaration);
  
  
  
          // Taking controller mouse input
          var Xin = Input.GetAxis ("Mouse X");
          var Yin = Input.GetAxis ("Mouse Y");
  
          LookAngleX += Xin * MouseSpeed;
          LookAngleY += Yin * MouseSpeed;
  
          LookAngleY = Mathf.Clamp (LookAngleY, -25f, 89f);
  
          Camera.transform.localEulerAngles = new Vector3(-LookAngleY, Zoffset, 0f);
          transform.eulerAngles = new Vector3(0f, LookAngleX, 0f);
          //transform.eulerAngles = new Vector3(0f, LookAngleX, 0f);
  
          Jump = 0f;
  
      }


Comment
Add comment · Show 2 · 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 Bonfire-Boy · Dec 13, 2017 at 12:33 AM 1
Share

That doesn't change the scope of those variables (well, apart from making them unavailable to some lines that aren't using them), so why do you think it would help?

avatar image KittenSnipes Bonfire-Boy · Dec 13, 2017 at 12:34 AM 0
Share

Just because of how weird if statements work. I think that it is a possibility but I was just throwing it out there. It is quite a weird error. I just moved the called variables closer to the lines of code that use them. I just wanted to at least throw out a suggestion rather than leave the question unanswered.

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

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

Related Questions

"The name does not exist in the current context" error 1 Answer

Assets/Scripts/PlayerController.cs(29,22): error CS1547: Keyword `void' cannot be used in this context 1 Answer

Getting errors while creating a custom terrain editor 0 Answers

the name "whichnote" does not exist in it's current context 1 Answer

"The name 'Convert' does not exist in the current context" C# 2 Answers


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