Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ScriptNameHere : MonoBehaviour
- {
- public float moveSpeed;//If you're going to edit this variable in a start function like how Aaron did, then make this variable private
- void FixedUpdate()//FixedUpdate should be used instead of Update while dealing with a RigidBody
- {
- float h = Input.GetAxis("Horizontal");
- float v = Input.GetAxis("Vertical");
- Rigidbody rb = GetComponent<Rigidbody>();
- rb.AddForce(h * moveSpeed * Time.fixedDeltaTime, 0.0f, v * moveSpeed * Time.fixedDeltaTime);//Make sure you have a RigidBody
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement