Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 guslindell2 · Mar 04, 2018 at 04:17 AM · scripting problemvariablecontrollerfpscontrollerother script

How to change the walk speed of the FPSController from another script?

I've been searching for an answer to this question for literal hours, and every answer is similar or the same, and it never works. I'm using the standard unity (version 2017.1.0f3) FPSController, and I'm trying to access the walkspeed and runspeed variables from another script. Almost every answer said that once you have the FirstPersonController saved as a variable, you can just do "controller.m_walkspeed = 0". This doesn't work for me. Whenever I try this, it highlights the "m_walkSpeed" or the "walkSpeed"*in red and gives me an

  "error CS1061: Type 'UnityStandardAssets.Characters.FirstPerson.FirstPersonController' does not contain a definition for 'm_walkSpeed' and no extension method 'm_walkSpeed' of type 'UnityStandardAssets.Characters.FirstPerson.FirstPersonController' could be found. Are you missing an assembly reference?"

error. This seems to work for everybody else without a hitch, and I don't understand why it refuses to work for me. Any help would be appreciated. Here's the full code if that will help:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityStandardAssets.Characters.FirstPerson;
 
 public class pressButton : MonoBehaviour {
 
 
     void Start() {
         
     }
     //joystick definitions
     public FirstPersonController controller;
     public Canvas reticule;
     //button definitions
     public Animator anim;
     GameObject hitObject;
     RaycastHit hitInfo;
     void Update () {
         Ray myRay = new Ray (transform.position, transform.forward);
         if(Physics.Raycast (myRay, out hitInfo))
         {
             hitObject = hitInfo.collider.gameObject;
             Debug.Log (hitObject.tag);
             if (hitObject.tag == "button") 
             {
                 if (Input.GetMouseButtonDown (0)) 
                 {
                     anim = hitObject.GetComponent<Animator> ();
                     anim.SetTrigger ("pressButton");
                     
                 }
             }
             if (hitObject.tag == "joystick") {
                 if (Input.GetMouseButtonDown (0)) 
                 {
                     reticule.enabled = false;
                     controller.m_walkSpeed = 0;
                 }
 
             }
             if (Input.GetMouseButtonUp (0) && reticule.enabled == false) {
                 reticule.enabled = true;
             }
         }
     }
 }

Comment
Add comment · Show 1
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 hexagonius · Mar 04, 2018 at 06:59 AM 0
Share

Have you actually looked into the code of the controller, checked what the name of variables actually are and what access modifier they're using?

2 Replies

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

Answer by GoneMadStudios · Mar 04, 2018 at 11:53 AM

I never used FirstPersonController, so I may be wrong, but it seems that you have not referenced any FirstPersonController, so you are trying to access the class itself, and not an instance of it.

If the FirstPersonController is in the same GameObject as your pressButton script, you should reference the controller in your Start() function:

void Start() { controller = GetComponent<FirstPersonController>(); }

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 guslindell2 · Mar 04, 2018 at 03:07 PM 0
Share

Okay, I feel really rediculously stupid. m_WalkSpeed has to be capitalized like that. I was typing m_walkSpeed. Thank you!

avatar image
2

Answer by EddyDavila · Sep 19, 2018 at 07:04 AM

If it helps anyone, the problem is that the walkSpeed and runSpeed are declared as private variables in the FirstPersonController script. Just make them public as a quick fix.

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 mechanic_kharkov · May 30, 2019 at 07:43 PM 0
Share

It's strange, but how does unity editor know that private float m_WalkSpeed; have to be shown in the properties explorer as "Walk speed" and also it's bold. $$anonymous$$aybe someone knows where the magic lives, and how can I use this WalkSpeed from outside without editing the standard class?

avatar image SkynixDev mechanic_kharkov · Feb 06, 2021 at 11:47 AM 0
Share

The m_WalkSpeed is private field but look at the the keyword SerializeField:

[SerializeField] private float m_WalkSpeed;

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

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

pubblic variable don't get change from script with OnTriggerStay 1 Answer

Cannot access AudioSource from within function 0 Answers

Question about moving an object technique 3 Answers

(PLAYMAKER) How to synchronize global variables to another visual scripting? (like Uscript or Behavior Machine Pro) 0 Answers

Limit number of face buttons being simultaneously held. 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