Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System.Collections;
using UnityEngine;

public class playercontroller : 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); 
      }
}


What I have tried:

I have tried debugging, retyping lines in a different way, and I have even triple checked to make sure that all of the components are set the way that they are supposed to be.
Posted
Updated 12-Nov-17 7:05am
v2

Learn to indent properly your code, it show its structure and it helps reading and understanding.
C#
using System.Collections;
using UnityEngine;

public class playercontroller : 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);
    }
  }

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]

The answer should be obvious with formatting and a little analyze of what is what.
 
Share this answer
 
public class playercontroller : MonoBehaviour
{

    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    } //add this closing bracket 
    void FixedUpdate()
    {
        float moveHorizontal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        rb.AddForce(movement);
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900