- Home /
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);
}
}
Furthermore, you should always use UpperCamelCase when na$$anonymous$$g classes. I.e. Player$$anonymous$$ove and Player$$anonymous$$ove.cs
Answer by Tricky7991 · Sep 11, 2014 at 05:03 PM
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.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Time.DeltaTime doesn't seem to be correctly 1 Answer