c# move with arrow keys
C#
//When you are using this code make sure it is for unity :) also make sure to
//subscribe to my channel KhalidDev. I will appreciate a lot :)
public class PlayerMovement : MonoBehaviour {
// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardAndBackForce = 500f; // Variable that determines the forward force
public float sidewaysForce = 500f; // Variable that determines the sideways force
// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate ()
{
if (Input.GetKey("d")) // If the player is pressing the "d" key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("a")) // If the player is pressing the "a" key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("w")) // If the player is pressing the "w" key
{
// Add a force to the Forward
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
}
if (Input.GetKey("s")) // If the player is pressing the "s" key
{
// Add a force to the back
rb.AddForce( 0, 0, -forwardForce * Time.deltaTime);
}
}
}
Also in C#:
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- unity onclick object
- Category
- C#
- Title
- c# mailmessage set sender name
- Category
- C#
- Title
- unity 2d detect click on sprite
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- unity mouse click position
- Category
- C#
- Title
- populate combobox from array c#
- Category
- C#
- Title
- unity how to make jump script
- Category
- C#
- Title
- c# singleton
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- x angle oes back after 90 unity
- Category
- C#
- Title
- edit form item from class C#
- Category
- C#
- Title
- mailkit send attachment
- Category
- C#
- Title
- c# to vb.net
- Category
- C#
- Title
- clear combobox c#
- Category
- C#
- Title
- what is using static in c#
- Category
- C#
- Title
- unity rb.addexplosionforce 2d
- Category
- C#
- Title
- how to add a gameobject
- Category
- C#
- Title
- epplus excel vb.net
- Category
- C#
- Title
- set object to random color unity
- Category
- C#
- Title
- how to get array of children transform
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- create dropdown in datatable c# dynamically
- Category
- C#
- Title
- object escape player unity
- Category
- C#
- Title
- if entity.is Transient() Update Mvc 5 c#
- Category
- C#
- Title
- c# 2 timespan return yesterday
- Category
- C#
- Title
- radians to degree c#
- Category
- C#
- Title
- c# for loop without increment
- Category
- C#
- Title
- unity particle system color
- Category
- C#
- Title
- sort c#
- Category
- C#
- Title
- player script unity
- Category
- C#
- Title
- c# checksum
- Category
- C#
- Title
- c# how to refresh your binding source
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- c# sql duplicate key exception
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- assign datasource to dropdownlist in c#
- Category
- C#
- Title
- get web config key value in c# razor view
- Category
- C#
- Title
- unity how to get y value
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- how to destroy a gameobject after some hits in unity 3d
- Category
- C#
- Title
- c# reverse a string
- Category
- C#
- Title
- unity instantiate
- Category
- C#
- Title
- unity round vector 3 to nearest integer
- Category
- C#
- Title
- unity if gameobject exists
- Category
- C#
- Title
- c# linq select from object list
- Category
- C#
- Title
- c# type of generic is string
- Category
- C#
- Title
- unity transfoprm position y change
- Category
- C#
- Title
- linq c# object except two lists
- Category
- C#
- Title
- c# create new thread
- Category
- C#
- Title
- C# .NET Core linq Distinct
- Category
- C#
- Title
- c# negation
- Category
- C#
- Title
- c# close window
- Category
- C#
- Title
- enums c#
- Category
- C#
- Title
- inheritance in c#
- Category
- C#
- Title
- c# how to open file explorer
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- increase variable C#
- Category
- C#
- Title
- c# check if type implements interface
- Category
- C#
- Title
- c# save pdf to folder
- Category
- C#
- Title
- c# list tuple
- Category
- C#
- Title
- unity t-flip flop
- Category
- C#
- Title
- query into complex object using dapper
- Category
- C#
- Title
- c# trim string
- Category
- C#
- Title
- how to spawn coins randomly around the screen unity 2d
- Category
- C#
- Title
- winforms timer c#
- Category
- C#
- Title
- c# polymorphism
- Category
- C#
- Title
- c# zip a file
- Category
- C#
- Title
- how to set a transform equal to something unity
- Category
- C#
- Title
- get permission to write read file and directory on file system C#
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- c# graphics draw filled rectangle
- Category
- C#
- Title
- stop unity editor playing
- Category
- C#
- Title
- how to stop a form c#
- Category
- C#
- Title
- unity get data from firebase
- Category
- C#
- Title
- C# check many strings quickly
- Category
- C#
- Title
- c# read excel file
- Category
- C#
- Title
- create line in unity
- Category
- C#
- Title
- stop ui from clipping wall
- Category
- C#
- Title
- how to reload app.config file at runtime in c#
- Category
- C#
- Title
- how to clear console in c#
- Category
- C#
- Title
- how to find the type of a object c#
- Category
- C#
- Title
- lat long data type c#
- Category
- C#
- Title
- xml node update attribute value c#
- Category
- C#
- Title
- c# how to compare 2 dates without time
- Category
- C#
- Title
- C# array to label
- Category
- C#
- Title
- format phone number in c# .net
- Category
- C#
- Title
- c# listview
- Category
- C#
- Title
- nullreferenceexception c#
- Category
- C#
- Title
- internal c#
- Category
- C#
- Title
- how to convert a number to 2 decimal places in c#
- Category
- C#
- Title
- c# linq order by multiple columns
- Category
- C#
- Title
- how to compare datetime in c#
- Category
- C#
- Title
- c# byte array to bitmap
- Category
- C#
- Title
- c# creating exceptions
- Category
- C#
- Title
- C# .net core convert int to enum
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- c# asp.net hover tooltip
- Category
- C#
- Title
- dynamic convert type c#
- Category
- C#
- Title
- unity simple fps controller
- Category
- C#