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 Mensley · Nov 27, 2014 at 11:29 AM · not workingwalkingrunning

Run and Walk Script not working

Hey everyone I have a walk/run script and I am getting an error which is stopping the script from working. I have looked through it and rewrote it and it still the same error the script I am using is:

 #pragma strict
 @script RequireComponent( AudioSource )
  
 var walkSounds : AudioClip[];
 var runSounds : AudioClip[];
  
 var walkAudioSpeed : float = 0.4;
 var runAudioSpeed : float = 0.2;
  
 private var walkAudioTimer : float = 0.0;
 private var runAudioTimer : float = 0.0;
  
 var isWalking : boolean = false;
 var isRunning : boolean = false;
  
 var walkSpeed: float = 8; // regular speed
 var runSpeed: float = 20; // run speed
  
 private var chCtrl: CharacterController;
 private var chMotor: CharacterMotor;
  
 function Start()
 {
     chCtrl = GetComponent(CharacterController);
     chMotor = GetComponent(CharacterMotor);
 }
  
 function Update()
 {
     SetSpeed();
      
     if ( chCtrl.isGrounded )
     {
         PlayFootsteps();
     }
     else
     {
         walkAudioTimer = 1000.0;
         runAudioTimer = 1000.0;
     }
 }
  
 function SetSpeed()
 {
     var speed = walkSpeed;
      
     if ( chCtrl.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift") )
     {
         speed = runSpeed;
     }
      
     chMotor.movement.maxForwardSpeed = speed;
 }
  
 function PlayFootsteps()
 {
     if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ) )
     {
         if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) )
         {
             // Running
             isWalking = false;
             isRunning = true;
         }
         else
         {
             // Walking
             isWalking = true;
             isRunning = false;
         }
     }
     else
     {
         // Stopped
         isWalking = false;
         isRunning = false;
     }
      
     // Play Audio
     if ( isWalking )
     {
         if ( walkAudioTimer > walkAudioSpeed )
         {
             audio.Stop();
             audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
             audio.Play();
             walkAudioTimer = 0.0;
         }
     }
     else if ( isRunning )
     {
         if ( runAudioTimer > runAudioSpeed )
         {
             audio.Stop();
             audio.clip = runSounds[ Random.Range( 0, runSounds.Length ) ];
             audio.Play();
             runAudioTimer = 0.0;
         }
     }
     else
     {
         audio.Stop();
     }
      
     // increment timers
     walkAudioTimer += Time.deltaTime;
     runAudioTimer += Time.deltaTime;
 }
 

If someone else could look over this maybe you can spot something I couldn't

Thanks

Edit Sorry Forgot the error code

NullReferenceException: Object reference not set to an instance of an object PlayerRunAndFootsteps.SetSpeed () (at Assets/Slender/Scripts/PlayerRunAndFootsteps.js:58) PlayerRunAndFootsteps.Update () (at Assets/Slender/Scripts/PlayerRunAndFootsteps.js:36)

Comment
Add comment · Show 6
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 Mensley · Nov 28, 2014 at 10:36 PM 0
Share

Thank you here is the error code NullReferenceException: Object reference not set to an instance of an object PlayerRunAndFootsteps.SetSpeed () (at Assets/Slender/Scripts/PlayerRunAndFootsteps.js:58) PlayerRunAndFootsteps.Update () (at Assets/Slender/Scripts/PlayerRunAndFootsteps.js:36)

avatar image Mensley · Nov 28, 2014 at 11:51 PM 0
Share

It seemed to stop working after I installed Unistorm before that it worked fine. I sorta need both of them

avatar image kdubnz · Nov 29, 2014 at 12:29 AM 0
Share

In your original .JS file the errors are in Update() line 36 and SetSpeed() line 58.

These line don't relate to your posted code. Can you advise the line numbers in the posted code that error.

Also any other information ( like the 'Unistorm' install ) that may be relevant may be handy.

I'm new to Unity and prefer cs to js so I may not actually be able to help you.

avatar image Mensley · Nov 29, 2014 at 03:31 AM 0
Share

Object reference not set to an instance of an object PlayerRunAndFootsteps.SetSpeed () (at Assets/Slender/Scripts/PlayerRunAndFootsteps.js:52 PlayerRunAndFootsteps.Update () (at Assets/Slender/Scripts/PlayerRunAndFootsteps.js:30

avatar image kdubnz · Nov 29, 2014 at 04:53 AM 0
Share

Do you have a Character$$anonymous$$otor script attached to your component ? Have you made modifications to it ? Is there also one provided by the 'Unistorm' install ?

just a wildassedguess.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by kdubnz · Nov 28, 2014 at 11:10 PM

Does this help ?
http://answers.unity3d.com/questions/373508/footsteps-script-for-running-and-walking.html

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

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

Footsteps Script for Running and Walking 3 Answers

I have a Multiplayer script here 1 Answer

Unity If statement issue (It goes through the function without meeting the parameters for the if statements) 2 Answers

Walking sound Script returns with Error: BCE0077 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