watair
1
import UnityEngine;
public var walkSpeed : float = 15f;
function Update () {
if(Input.GetKey(KeyCode.D))
{
transform.Translate(new Vector3(walkSpeed, 0, 0) * Time.deltaTime);
}
if(Input.GetKey(KeyCode.A))
{
transform.Translate(new Vector3(-walkSpeed, 0, 0) * Time.deltaTime);
}
}
transform.position not transform.Position
Capitalization is important.
Paplexa
3
Try transform.Translate instead of transform.Position
@watair
Your script has many errors. I highly recommend you being by following some tutorials: Learn Game Development Without Coding Experience | Unity
At a glance:
-
input
needs to be Input
-
Position
needs to be position
-
new Vector2.forward(Vector2.forward * walkSpeed * Time.deltaTime)
should be just Vector2.forward * walkSpeed * Time.deltaTime
- The whole lot should be inside
Update()
, not Start()
I think you need to set it equal to the new position:
transform.position = new Vector2(Vector2.forward * walkSpeed * Time.deltaTime);