I was following a tutorial on how to make footsteps, and when I got to the “isGrounded” part in my script, it turned red. In the console it said that the CharacterController (which is another script) doesn’t have a definition for “isGrounded”. And it also said what I wrote in the title.
I googled it, and the only suggestion I could find was declaring stuff as public. But obviously that’s specific to every single code.
Here’s the CharacterController script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterController : MonoBehaviour {
bool isGrounded = true;
public float speed = 10.0f;
// Use this for initialization
void Start () {
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update () {
float translation = Input.GetAxis ("Vertical") * speed;
float straffe = Input.GetAxis ("Horizontal") * speed;
translation *= Time.deltaTime;
straffe *= Time.deltaTime;
transform.Translate (straffe, 0, translation);
if (Input.GetKeyDown ("escape")) {
Cursor.lockState = CursorLockMode.None;
}
}
}
And here is the script from the tutorial:
using UnityEngine;
using System.Collections;
public class Footsteps : MonoBehaviour {
CharacterController cc;
void Start () {
cc = GetComponent<CharacterController>();
}
void Update () {
if(cc.isGrounded == true && cc.velocity.magnitude > 2f && audio.isPlaying == false) {
audio.volume = Random.Range(0.8f, 1);
audio.pitch = Random.Range(0.8f, 1.1f);
audio.Play();
}
}
}
Anyone got any idea what the problem is in the CharacterController?
Also, you can’t access a transform velocity this way. Your script cc doesn’t know by itself that you attached à Rigidbody to the GameObject. You need to get its Rigidbody first :
That solved the “isGrounded” thing. But I just realized I still have a lot of other red areas, and errors. I’m just going to post them as screenshots, so people can see exactly what’s wrong now.
Here is the tutorial script in MonoDevelop:
And here are the errors in the console:
Hope you (or someone else) can help me with these.
If your script has a class of the same name, you’re going to run into conflicts where Unity thinks you want one but you actually want the other. Rename your script to something else.
Now I’m just left with the “audio” ones. Like “isPlaying” and stuff.
Any idea what to do about those?
I think I remember having audio issues in one of my previous projects, and having to do “GetComponent”, but I’m not sure. And I don’t have the files for that project anymore.
Now it says there’s no “CharacterController” attached to the player gameobject, but a script is trying to access it.
But when I add a CharacterController component to the player and run the game, it freaks out and I get launched into the air.
As I said, use Unity 4. A lot has changed and code has to be delt with differently. That is why when you import a unity 4 project into 5, it goes through your scripts and changes them for you.
Go through the entire tutorial in unity 4 as that is what it was made for. When it is finished and working, you can import it and see what gets changed. Using git or source control would make that quick and easy.
Instead of using "AudioSource. " (etc) on those few lines, use the variable that you assigned in Start()
that was GetComponent
WalkingOnDirtSoundEffect I think you called it
You’re trying to access non-static members using the class, not the instance/object (ie: variable).
And your one other red line error about the character controller, you’d have to repost the line in question to see what that’s about ; I couldn’t guess from this thread at this point