- Home /
Getting CS0117 error ... Help
I'm learning c# scripting and the book i'm following has the same code but it's not running for some reason...so please help me where i'm doing wrong .... Here is the code :-
using UnityEngine; using System.Collections;
public class Input : MonoBehaviour {
public Vector3 pos;
// Use this for initialization
void Start ()
{
pos = transform.position;
}
// Update is called once per frame
void Update ()
{
bool aKey = Input.GetKey (KeyCode.A);
bool dKey = Input.GetKey (KeyCode.D);
bool wKey = Input.GetKey (KeyCode.W);
bool sKey = Input.GetKey (KeyCode.S);
if (aKey)
{
pos.x = pos.x - 0.1f;
}
if (dKey)
{
pos.x = pos.x + 0.1f;
}
if (wKey)
{
pos.z = pos.z + 0.1f;
}
if (wKey)
{
pos.z = pos.z - 0.1f;
}
transform.position = pos;
}
}
and this is the error :-
Input.cs(20,35): error CS0117: Input' does not contain a definition for
GetKey'
Thanks :D
Answer by JigneshKoradiya · Mar 28, 2015 at 08:23 PM
change calls name
public class Input : MonoBehaviour
to
public class InputScript : MonoBehaviour
Yes, an Input class is already used by the Unity Engine and your Input class is masking it, to put it crudely.
Answer by amitkuliyal · Mar 29, 2015 at 07:10 AM
thanks guys it worked... i'm still confused of how you get to know what is making the errors in the code.
Your answer
Follow this Question
Related Questions
Help Ship Controll 0 Answers
how can i get a pause screen to work 0 Answers
Trying to make Collider Activate with key code 1 Answer
How do I make my player face the direction its moving. 0 Answers
Changing Force of object 1 Answer