Search Unity

First Time User

Discussion in 'Scripting' started by nooB, Oct 4, 2009.

  1. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    Hi all,

    I m kind of having a starting trouble.
    I wanted to implement a basic move function for a character using one of the animations. How can I get this done in C#.


    Nitin
     
  2. edplane

    edplane

    Joined:
    Jul 13, 2009
    Posts:
    485
    If you already know the C# language, just look at the scripting referance. Im new to, and im focusing more on JvaScript, so Im not sure exactly what to write. For a FPS controller, Unity has a built in JS script to control it in the Standard Assets folder.
     
  3. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    Thanx for the reply. But I wanted to implement my code in C# and gettin stuck in the

    GetComponent.



    Code (csharp):
    1. CharacterController controller = (CharacterController)gameObject.GetComponent(CharacterController);
    2.    
    3.    
    4.     controller.Move(moveDirection * Time.deltaTime);
    5.  
    6. What am I doing wrong?
     
  4. llde_chris

    llde_chris

    Joined:
    Aug 13, 2009
    Posts:
    205
    Code (csharp):
    1.  
    2. CharacterController controller = (CharacterController)gameObject.GetComponent("CharacterController");
    3.    
    4.    
    5.    controller.Move(moveDirection * Time.deltaTime);
    6.  
    You should use either "CharacterController" or typeof(CharacterController), not just CharacterController in the GetComponent parameters.
     
  5. nooB

    nooB

    Joined:
    Oct 4, 2009
    Posts:
    20
    Ah ! That worked :)

    Thanx a million
     
unityunity