- Home /
coding error
This error pops up Assets/Standard Assets/Character Controllers/Sources/Scripts/PlayerAnimate.js(8,29): BCE0020: An instance of type 'UnityEngine.GameObject' is required to access non static member 'GetComponent'.
my code is this #pragma strict
function Start () {
}
function Update () { var AT = GameObject.GetComponent(AnimateTexture); //Store AnimateTexture Script if(Input.GetKey("a")){ //Player moves left AT.rowNumber = 1; //Change to running animation } else if(Input.GetKey("d")){ //Player moves right AT.rowNumber = 1; //Change to running animation } else { //Player is not moving AT.rowNumber = 0; //Change to idle animation! }
}
Answer by KellyThomas · Dec 28, 2013 at 03:36 AM
Firstly please format you code next time (the button labeled "101010" will help) it can be tricky but keep working at it until your post preview shows it is formatted.
Your line:
var AT = GameObject.GetComponent(AnimateTexture);
Should be:
var AT = gameObject.GetComponent(AnimateTexture);
GameObject
is the class and is useful for accessing utility methods that have been implemented as static
e.g. GameObject.Find()
gameObject
is the variable used to access the GameObject
instance your script is attached to. It is useful for accessing methods that apply to this GameObject
e.g. gameObject.GetComponent()
Your answer
Follow this Question
Related Questions
No appropriate version of 'UnityEngine.Object.Instantiate. Please Help :( 1 Answer
Assets/Zombies/sharedassets0.asset(1,1): BCE0044: unexpected char: 0x0. Can anybody help me? 1 Answer
Ending my game 3 Answers
How can I convert this code to Unity Android? 1 Answer
CAN SOMEONE FINALLY HELP ME! 3 Answers