- Home /
How do I script movement for my player?
Hi I am trying to make a simple 2D platformer and I am having the hardest time trying to figure out how to get my block to move and when I think that I fixed it Unity says "An instance of type 'UnityEngine.Transform' is required to access non static member 'Translate'." all I want is for it to move left and right THATS ALL! Help!
public var movespeed = 5f;
function Update ()
{
if(Input.GetKeyDown(KeyCode.A)){
Transform.Translate(Vector3.left * movespeed * Time.deltaTime);
}
}
Answer by Landern · Mar 18, 2015 at 12:41 PM
You are using "Transform" like a type, if you want to modify the transform of the gameobject this script above is attached to, use:
transform.Translate(.....);
If you use the uppercase T version you are trying to make a call on the class as thought Translate function/method is a static.
Your answer
Follow this Question
Related Questions
Audio for movement 1 Answer
How can I make my characters movement better? 1 Answer
Why do I double jump? This isn't supposed to happen... 2 Answers
Face player right/left 1 Answer
2D 360 degress platformer example needed 0 Answers