Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Missing components?

Discussion in 'Editor & General Support' started by jaryd4, Jun 8, 2015.

  1. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    Hi there

    I am busy coding to make my character move around and jump. However when it comes to my CharacterController.isGrounded I get an error that it does not exist, and is inaccessible due to its protection level. Screenshot 2015-06-08 08.07.19.png Screenshot 2015-06-08 08.07.19.png

    Screenshot 2015-06-08 08.07.35.png As you can see I am working on a mac, this issue is not occurring on a classmates computer which is running windows. Could it only be a mac issue? any ideas how to fix this will be greatly appreciated
     
  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    You should post your charactercontroller.cs, not the other ones
     
  3. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    Here is the entire script.

    usingUnityEngine;
    usingSystem.Collections;

    publicclassTestCharacterScript : MonoBehaviour
    {

    publicfloatmoveSpeed = 10f; //walkspeedofcharacter.
    publicfloatrotateSpeed = 180f;
    publicfloatjumpSpeed = 20f;
    publicfloatgravity = 9.8f;

    publicCharacterControllermycontroller;

    Vector3currentMovement;


    voidStart ()
    {
    mycontroller = GetComponent<CharacterController>();

    }

    voidUpdate ()
    {
    transform.Rotate (0, Input.GetAxis ("Horizontal") * rotateSpeed * Time.deltaTime, 0);

    currentMovement = newVector3 (0, currentMovement.y, Input.GetAxis ("Vertical") * moveSpeed);

    //currentMovement.z = Input.GetAxis (“Vertical”) * moveSpeed);} anotherwaytowritethecodeabovethisone.
    //currentMovement.x = 0; }


    currentMovement = transform.rotation * currentMovement;

    if (!mycontroller.isGrounded)
    {
    currentMovement -= newVector3 (0, gravity * Time.deltaTime, 0);

    }
    else
    currentMovement.y = 0;

    if (mycontroller.isGrounded && Input.GetButtonDown ("Jump"))
    {
    currentMovement.y = jumpSpeed;
    }
    mycontroller.Move (currentMovement * Time.deltaTime);
    }
    }
     
  4. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    The problems I am having are that isGrounded and Move do not exist
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  6. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    We Need CharacterController.cs, not your TestCharacterScript.
     
  7. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestCharacterScript : MonoBehaviour
    5. {
    6.    
    7.     public float moveSpeed = 10f;  // walk speed of character.
    8.     public float rotateSpeed = 180f;
    9.     public float jumpSpeed = 20f;
    10.     public float gravity = 9.8f;
    11.  
    12.     public CharacterController mycontroller;
    13.    
    14.     Vector3 currentMovement;
    15.  
    16.    
    17.     void Start ()
    18.     {
    19.         mycontroller = GetComponent<CharacterController>();
    20.  
    21.     }
    22.    
    23.     void Update ()
    24.     {
    25.         transform.Rotate (0, Input.GetAxis ("Horizontal") * rotateSpeed * Time.deltaTime, 0);
    26.        
    27.         currentMovement =  new Vector3 (0, currentMovement.y, Input.GetAxis ("Vertical") * moveSpeed);
    28.        
    29.         // currentMovement.z =   Input.GetAxis (“Vertical”) * moveSpeed);}   another way to write the code above this one.
    30.         // currentMovement.x = 0;                                         }
    31.        
    32.        
    33.         currentMovement = transform.rotation * currentMovement;
    34.        
    35.         if (!mycontroller.isGrounded)
    36.         {
    37.             currentMovement -= new Vector3 (0, gravity * Time.deltaTime, 0);
    38.    
    39.         }  
    40.         else
    41.             currentMovement.y = 0;
    42.        
    43.         if (mycontroller.isGrounded && Input.GetButtonDown ("Jump"))
    44.         {
    45.             currentMovement.y = jumpSpeed;
    46.         }
    47.         mycontroller.Move (currentMovement * Time.deltaTime);      
    48.     }
    49. }
    50.  
     
  8. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    sorry about that, I'm new to asking on the forums haha
     
  9. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    1. There is no need for double posts, just edit your last post and add to it.
    2. In case you have your own class named CharacterController, just rename it or you get a collsion with the unity build in CharacterController class (with does have the isGrounded variable).
    .

    If you do not have your CharacterController class , please post the whole error message you get from the console.
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I just noticed that you are showing the error messages from MonoDevelop. Those can sometimes be misleading and wrong. Do you get the same messages in Unity? If yes, what exactly is the first error message in Unity.
     
  11. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    I do get them in unity, and the first as follows; Screenshot 2015-06-08 21.52.14.png
     
  12. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    We need your CharacterController script (as I stated before) ;)
     
  13. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    hey @Carpe Denius my CharacterController script is there a few messages above.
     
  14. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    Hey everyone the issue has been resolved, I started a whole new unity project from scratch and it all worked. I am going to port it to my mac later to see if it'll work. Any ideas how this happened though??

    Thanks for all the help.
     
  15. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The issue is that Unity itself has a CharacterController, but you have another script in you project named CharacterController. That leads to a conflict. Don't name your script CharacterController and the issue will go away.
     
  16. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    I can only see that you posted "TestCharacterScript" several times, but I needed the other one called "CharacterController", because there are some private things which should be public to work.
     
  17. jaryd4

    jaryd4

    Joined:
    Feb 3, 2015
    Posts:
    9
    okay I see now, I changed the CharacterController script name and it all works perfectly, haha silly I didn't realise this. thanks for the help :D