Errors in unity with a movement script

okay so i got this little problem, i have created (tried at least) a movement script with the abilty of pushing objects with rigid body’s
and a spawnpoint for my character per lvl.
i have no experience since im a freshman at college.
i think it’s just a noob error, since unity wont allow me to use the script since it “doesnt exist”

i named the script pps.cs

using UnityEngine;
using System.Collections;

public class playermove : MonoBehaviour {
	public float pushPower = 2.0F;
	public float movementSpeed = 1.0F;

	void OnControllerColliderHit(ControllerColliderHit hit) {
				Rigidbody body = hit.collider.attachedRigidbody;
				if (body == null || body.isKinematic)
						return;
		
				if (hit.moveDirection.y < -0.3F)
						return;
		
				Vector3 pushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z);
				body.velocity = pushDir * pushPower;
		}
	// Use this for initialization
	void Start () {
		//player spawn point
		//this is where our player will spawn.
		transform.position = new Vector3 (85, 1, 55);
	}
	
	// Update is called once per frame
	void Update () {
		transform.Translate(Vector3.right * movementSpeed * Time.deltaTime);
		transform.Translate(Vector3.left * movementSpeed * Time.deltaTime);
		transform.Translate(Vector3.up * movementSpeed * Time.deltaTime);
		transform.Translate(Vector3.down * movementSpeed * Time.deltaTime);
	}
}

The name of the script should be the same as the class name, in your case the script should be called playermove.cs Alternatively, rename the class to the name of your script : public class pps : MonoBehaviour {

The name of the script has to match the name of the class: Rename your script to: playermove.cs

Furthermore, you should always use UpperCamelCase when naming classes. I.e. PlayerMove and PlayerMove.cs

1 Answer

1

The script needs to have the same name as the public class in the script. So just rename the script to PlayerMove.cs And change the public class to PlayerMove. Then unity should find it.