I’m reading a book on using Unity with C#, and in it, I’m trying to convert this, (it’s not the whole thing):
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed;
to C#. I have:
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
Vector3 moveDirection = (0, 0, 0);
bool grounded = false;
void FixedUpdate () {
if(grounded){
moveDirection = (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = TransformDirection(moveDirection);
moveDirection *= speed;
if(Input.GetButtonUp ("Jump")){
moveDirection.y = jumpSpeed;
}
In lines 9 and 14, it says that the “,” is an unexpected symbol when declaring my Vector3, moveDirection. Shouldn’t the commas be expected since it’s a Vector3?
moveDirection = new Vector3(…)
pjcarey97:
I’m reading a book on using Unity with C#, and in it, I’m trying to convert this, (it’s not the whole thing):
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
private var moveDirection : Vector3 = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed;
to C#. I have:
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
Vector3 moveDirection = (0, 0, 0);
bool grounded = false;
void FixedUpdate () {
if(grounded){
moveDirection = (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = TransformDirection(moveDirection);
moveDirection *= speed;
if(Input.GetButtonUp ("Jump")){
moveDirection.y = jumpSpeed;
}
In lines 9 and 14, it says that the “,” is an unexpected symbol when declaring my Vector3, moveDirection. Shouldn’t the commas be expected since it’s a Vector3?
this same script it’s actually on the unity scripting reference, if you open it and type move on the search bar then click on character controller.move you will see the script written correctly.