- Home /
problem was a simple fix of ctrl+c and ctrl+v
rollaball ball wont move
already consulted several posts on here, none work here's my script
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
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 * speed);
}
}
using UnityEngine; using System.Collections;
public class PlayerController : $$anonymous$$onoBehaviour {
public float speed;
private Rigidbody rb;
speed = 1.0f;
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 * speed);
}
}
currently looks like this error reads "Assets/script/playermovement.cs(4,14): error CS0101: The namespace global::' already contains a definition for
PlayerController' "
Then it's easy, just change the name of the script and class, for example PlayerController2
public class PlayerController2 : $$anonymous$$onoBehaviour
Edit: the name of the script has to be the same as the class name, according to the error, the script is called playermovement.cs ins$$anonymous$$d of PlayerController.cs
Assets/script/playermovement.cs(9,11): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
Answer by GuiDroid · Sep 01, 2017 at 04:19 PM
Has @haruna9x said, you need to set the speed value to anything higher than 0. Either go to the inspector and change it, or change it in the code, such as
void Start ()
{
rb = GetComponent<Rigidbody>();
speed = 1.0f;
}
fixed one error, now its saying that i cant use the "="
using UnityEngine; using System.Collections;
public class playermovement : $$anonymous$$onoBehaviour {
public float speed;
speed = 1.0f
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 * speed);
}
}
Answer by poodn · Sep 07, 2017 at 03:34 PM
problem fixed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!