move character unity
C#
using UnityEngine;
using System.Collections;
// This script moves the character controller forward
// and sideways based on the arrow keys.
// It also jumps when pressing space.
// Make sure to attach a character controller to the same game object.
// It is recommended that you make only one call to Move or SimpleMove per frame.
public class ExampleClass : MonoBehaviour
{
CharacterController characterController;
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
characterController = GetComponent<CharacterController>();
}
void Update()
{
if (characterController.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
// Apply gravity. Gravity is multiplied by deltaTime twice (once here, and once below
// when the moveDirection is multiplied by deltaTime). This is because gravity should be applied
// as an acceleration (ms^-2)
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
}
}
Also in C#:
- Title
- loop through an enum c#
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- C# .net core convert int to enum
- Category
- C#
- Title
- c# check if type implements interface
- Category
- C#
- Title
- unity make a int arry with preset values
- Category
- C#
- Title
- use enter key unity
- Category
- C#
- Title
- how to get array of children transform
- Category
- C#
- Title
- validating file upload asp.net core mvc
- Category
- C#
- Title
- change textbox location C#
- Category
- C#
- Title
- json serialize object capitalization config
- Category
- C#
- Title
- c# arraylist contains
- Category
- C#
- Title
- creating a c# class
- Category
- C#
- Title
- call Textboxfor in cs
- Category
- C#
- Title
- how to add a list to observablecollection in c#
- Category
- C#
- Title
- unity how to change the text on a button
- Category
- C#
- Title
- unity material offset script
- Category
- C#
- Title
- dynamic convert type c#
- Category
- C#
- Title
- c# how to refreshyour bindingsource
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- how do i limit the amount of prefabs in unity using c# script
- Category
- C#
- Title
- c sharp create dictionary
- Category
- C#
- Title
- c# get desktop path
- Category
- C#
- Title
- c# array isn't working
- Category
- C#
- Title
- unity vector3 smoothdamp not reaching target
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- c# how to compare 2 dates without time
- Category
- C#
- Title
- unity main texture not working
- Category
- C#
- Title
- c# list to string join
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- how to convert iformfile to byte array c#
- Category
- C#
- Title
- c# convert dictionary to anonymous object
- Category
- C#
- Title
- how to change text to bold through script unity
- Category
- C#
- Title
- example HttpClient c# Post
- Category
- C#
- Title
- c# convert column name to number
- Category
- C#
- Title
- c# empty IEnumerable
- Category
- C#
- Title
- how to add a gameobject
- Category
- C#
- Title
- how to turn a string in a char list c#
- Category
- C#
- Title
- unity how to get data of play session time in a text file?
- Category
- C#
- Title
- entity framework core
- Category
- C#
- Title
- how to load the active scene unity
- Category
- C#
- Title
- how to remove space between string in c#
- Category
- C#
- Title
- c# compile into an exe
- Category
- C#
- Title
- how to check if a value is inside an array c#
- Category
- C#
- Title
- set object to random color unity
- Category
- C#
- Title
- linq c# or
- Category
- C#
- Title
- how to make a pause feautre in unity
- Category
- C#
- Title
- unity how to get y value
- Category
- C#
- Title
- c# convert to int
- Category
- C#
- Title
- get permission to write read file and directory on file system C#
- Category
- C#
- Title
- delegate function c#
- Category
- C#
- Title
- how to cjeck if a string has a word c#
- Category
- C#
- Title
- c# interview questions
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- unity how to rotate something to point to something else
- Category
- C#
- Title
- Could not load file or assembly 'Ubiety.Dns.Core, Version=2.2.1.0
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- c# expression func automatically select return type
- Category
- C#
- Title
- reload current scene unity
- Category
- C#
- Title
- unity delete specific text in a string
- Category
- C#
- Title
- c# scene manager
- Category
- C#
- Title
- how to make an array in csharp
- Category
- C#
- Title
- parsing string to int without format exception c#
- Category
- C#
- Title
- unity3d find y position on navmesh
- Category
- C#
- Title
- create line in unity
- Category
- C#
- Title
- asp.net mvc 5 codefirst dropdown list
- Category
- C#
- Title
- unity get velocity at point
- Category
- C#
- Title
- c# creating exceptions
- Category
- C#
- Title
- c# ref
- Category
- C#
- Title
- xamarin forms alarm
- Category
- C#
- Title
- unity hide mouse
- Category
- C#
- Title
- what data type should be for contact number in asp.net
- Category
- C#
- Title
- c# md5 string
- Category
- C#
- Title
- image filter
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- object escape player unity
- Category
- C#
- Title
- button color uwp c#
- Category
- C#
- Title
- c# loop through object
- Category
- C#
- Title
- split on uppercase c#
- Category
- C#
- Title
- c# check if string is only letters and numbers
- Category
- C#
- Title
- how to add system.messaging c#
- Category
- C#
- Title
- c# console delay
- Category
- C#
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- microsoft input tool need .net framework
- Category
- C#
- Title
- resize image c#
- Category
- C#
- Title
- convert comma separated string to array c#
- Category
- C#
- Title
- rotate object towards target rotation slowly unity
- Category
- C#
- Title
- string format comma c#
- Category
- C#
- Title
- unity add component
- Category
- C#
- Title
- c# int
- Category
- C#
- Title
- unity normalize vector2
- Category
- C#
- Title
- c# main method
- Category
- C#
- Title
- unity movetowards 2d
- Category
- C#
- Title
- unity on mousewheel down
- Category
- C#
- Title
- top down movement unity c#
- Category
- C#
- Title
- c sharp check if key in dictionary
- Category
- C#
- Title
- c# windows grab screenshot
- Category
- C#
- Title
- dontdestroyonload unity
- Category
- C#
- Title
- c# get all class properties
- Category
- C#