Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

CharacterController

Discussion in 'Editor & General Support' started by AlbertoT, Mar 28, 2010.

  1. AlbertoT

    AlbertoT

    Joined:
    Mar 27, 2009
    Posts:
    159
    hello

    In javaScript you write

    var controller : CharacterController = GetComponent(CharacterController);

    controller.Move(moveDirection * Time.deltaTime);

    What shall I do using C# ?
     
  2. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    Code (csharp):
    1.  
    2. CharacterController controller = GetComponent<CharacterController>();
    3. controller.Move(moveDirection * Time.deltaTime);
    4.  
    There are other ways of calling GetComponent but I prefer the generic method, unless this is for the IPhone.
     
  3. AlbertoT

    AlbertoT

    Joined:
    Mar 27, 2009
    Posts:
    159
    thanks
    It is what I did but it does not work
    I get the error message : a variable is expected...
     
  4. sybixsus2

    sybixsus2

    Joined:
    Feb 16, 2009
    Posts:
    943
    I'm not familiar with that error. Are you sure you're not writing C# code in a Javascript behaviour? In order to write C#, you have to create a C# behaviour. You can't just edit a Javascript behaviour because it will still expect to find Javascript there.
     
  5. AlbertoT

    AlbertoT

    Joined:
    Mar 27, 2009
    Posts:
    159
    well I have created a Sharp script so I suppose to be in C# also I wrote some "struct" no problem
    I tried also

    CharacterController controller = (CharacterController) GetComponent(typeof(CharacterController));

    No error message , but when I add

    controller.Move();

    I get the message

    Expression denote a type where a variable, value or method group was expected

    First time for me to use C# with Unity3d but I suppose that all Unity3d / C# users know the answer

    At least one to support , please :D
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Can you post the whole script?