Search Unity

C# - Access CharacterMotor Script

Discussion in 'Scripting' started by TheftAdi, Jul 24, 2014.

  1. TheftAdi

    TheftAdi

    Joined:
    Jul 24, 2014
    Posts:
    10
    Hello,

    First of all my english is not the best because i'm from Germany.
    I want to change the 'MaxForwardSpeed' Variable in the CharacterMotor Script coming with the First Person Character.

    Code (CSharp):
    1. public float SprintSpeed = 0;
    2.     float CharSpeed;
    3.  
    4.     void Start()
    5.     {
    6.         CharSpeed = GetComponent<CharacterMotor>().movement.maxForwardSpeed;
    7.     }
    8.  
    9.     void Update()
    10.     {
    11.  
    12.     }
    I've tried it so many times in many different projects but i just won't work, the error:
    The name 'CharacterMotor' does not exists in the current context.

    Can anyone help me? :(
     
  2. TheftAdi

    TheftAdi

    Joined:
    Jul 24, 2014
    Posts:
    10
    No one? :/
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    1) your code wouldn't set the maxForwardSpeed, it retrieves the maxForwardSpeed

    2) "The name 'CharacterMotor' does not exist in the current context" is saying that it doesn't recognize the word 'CharacterMotor'. This could happen for a number of reasons, for instance if CharacterMotor existed in another namespace... but it doesn't, it should exist in the global namespace.

    BUT

    I do know that CharacterMotor is written in UnityScript and not C#. For one to access the other, the one being accessed must be compiled before the other as C# and UnityScript aren't compiled together (I know, it's really annoying).

    Here is the compilation order:
    http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html

    CharacterMotor usually comes in the 'Standard Assets' folder if you import it through the package manager. Make sure that your script is NOT in the 'Standard Assets'. This means the CharacterMotor will compile first, and your script after, and your script can access it then.