• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by TheDemin · Feb 28, 2014 at 01:14 AM · c#namespacetype

Type or namespace 'CharacterMotor' cannot be found

This is my RunningSound code, which uses triggers to play 'walking' and 'running' sounds. The problem is, I have no idea how to fix the CharacterMotor error I keep getting at runtime. The CharacterMotor and this file are in the same folder in the Standard Assets file, and the file below is a C# file, while the CharacterMotor is a Javascript file. Any suggestions on what I should do? Thank you in advance for your help.

 using UnityEngine;
 using System.Collections;
 using CharacterMotor;//Unsure of this area, does not seem to do anything. 
 //Still here to show it does not work.
 
 [RequireComponent(typeof(AudioSource))]
 
 public class WalkingSoundScript : MonoBehaviour {
  
 AudioClip walk;
 AudioClip run;
  
 float walkAudioSpeed = 0.4f;
 float runAudioSpeed = 0.2f;
  
 private float walkAudioTimer = 0.0f;
 private float runAudioTimer = 0.0f;
  
 bool  isWalking = false;
 bool  isRunning = false;
  
 float walkSpeed = 7; // regular speed
 float runSpeed = 20; // run speed
  
 private CharacterController chCtrl;
 private CharacterMotor chMotor;//Note that CharacterMotor is a Javascript file, and is not considered an object.
  
 void  Start (){
     chCtrl = GetComponent<CharacterController>();
     chMotor = GetComponent<CharacterMotor>();
 }
  
 void  Update (){
     SetSpeed();
  
     if ( chCtrl.isGrounded )
     {
         PlayFootsteps();
     }
     else
     {
         walkAudioTimer = 0.0f;
         runAudioTimer = 0.0f;
     }
 }
  
 void  SetSpeed (){
     float speed= walkSpeed;
  
     if ( chCtrl.isGrounded && Input.GetKey("left shift") || Input.GetKey("right shift") )
     {
         speed = runSpeed;
     }
  
     chMotor.movement.maxForwardSpeed = speed;
 }
  
 void  PlayFootsteps (){
     if ((Input.GetAxis( "Horizontal" )>0) || (Input.GetAxis( "Vertical" )>0) )
     {
        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 ( audio.clip != walk )
        {
          audio.Stop();
          audio.clip = walk;
        }
  
        //if ( !audio.isPlaying )
        if ( walkAudioTimer > walkAudioSpeed )
        {
          audio.Stop();
          audio.Play();
          walkAudioTimer = 0.0f;
        }
     }
     else if ( isRunning )
     {
        if ( audio.clip != run )
        {
          audio.Stop();
          audio.clip = run;
        }
  
        //if ( !audio.isPlaying )
        if ( runAudioTimer > runAudioSpeed )
        {
          audio.Stop();
          audio.Play();
          runAudioTimer = 0.0f;
        }
     }
     else
     {
        audio.Stop();
     }
  
     // increment timers
     walkAudioTimer += Time.deltaTime;
     runAudioTimer += Time.deltaTime;    
     }
 }
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

Answer by rutter · Feb 28, 2014 at 01:15 AM

Unity does allow some interaction between C# and JS files, but it's very limited. Unity compiles your scripts in several stages. One script can "see" the other if it's compiled in an earlier stage. You can find a list of compilation stages here.

If this is your only cross-language dependency, you can probably just move WalkingSoundScript out of Standard Assets.

If you have a lot of dependencies, things can get ugly. I try to stick to one language for a project.

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 TheDemin · Feb 28, 2014 at 03:43 AM 0
Share

Thankfully, it is the only dependency I have. I have moved it out of the Standard Asset folder. The problem is, it becomes a repeat of a previous error that I had before: A NullReferenceError. I did not intend on repeating this error, so I will simply link back to it to avoid repeating myself across multiple questions and wasting everyone's time. Thank you for your assistance though.

http://answers.unity3d.com/questions/648014/nullrefernceerror-in-walkingsound.html

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Error the type or namespace name 1 Answer

Name GUI input help in C# 0 Answers

Is script a child of another certain script? 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