- Home /
What am i doing wrong?!?!?!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playercontroler : MonoBehaviour { private Rigidbody rb;
void start()
{
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("horizontal");
float moveVertical = Input.GetAxis ("vertical");
Vector3 movement = New Vector3 ("moveHorizontal, 0.0f, moveVertical");
rb.AddForce (movement);
}
}
I am getting an error saying that the second Vector3 in the second to last line is unexpected. what does that mean i have rewritten the whole code twice and i am still getting the error.
Answer by Cynikal · Jun 17, 2017 at 05:57 AM
You have the new vector3 as a string...
You'd want to have it:
Vector3 movement = New Vector3 (moveHorizontal, 0.0f, moveVertical);
...However, I still don't think it's going to produce the results you want.
Also, "New" should not be capitalized, and this code should probably go in Update(), not FixedUpdate(), since it is taking input.
Also, start()
should be Start()
(with capital "s"), otherwise it won't be executed at the start (afaik) and thus the line rb.AddForce (movement);
will cause a null reference error.
Your answer
Follow this Question
Related Questions
EntityQuery a specific Archetype 1 Answer
How to convert a curl query to wwwform 2 Answers
Linq Query - Strange Outcome 1 Answer
Query Related to Virtual Keyboard 0 Answers
Delay in approval 1 Answer