Advertisement
Guest User

Unity C# Simple Move Script

a guest
Jun 27th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ScriptNameHere : MonoBehaviour
  5. {
  6.     public float moveSpeed;//If you're going to edit this variable in a start function like how Aaron did, then make this variable private
  7.  
  8.     void FixedUpdate()//FixedUpdate should be used instead of Update while dealing with a RigidBody
  9.     {
  10.         float h = Input.GetAxis("Horizontal");
  11.         float v = Input.GetAxis("Vertical");
  12.         Rigidbody rb = GetComponent<Rigidbody>();
  13.         rb.AddForce(h * moveSpeed * Time.fixedDeltaTime, 0.0f, v * moveSpeed * Time.fixedDeltaTime);//Make sure you have a RigidBody
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement