movement script c#
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
- C# .NET Core linq Distinct
- Category
- C#
- Title
- how to make error sound c#
- Category
- C#
- Title
- c# string to float
- Category
- C#
- Title
- ping with c#
- Category
- C#
- Title
- read configuration workerservice
- Category
- C#
- Title
- how to get object to spawn in a curcle
- Category
- C#
- Title
- how to add object in dictionary in c#
- Category
- C#
- Title
- snake game
- Category
- C#
- Title
- c# remove character from string at index
- Category
- C#
- Title
- c# yield
- Category
- C#
- Title
- convert number of days into months c#
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- delegate function c#
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- how to disable a gameObject unity c#
- Category
- C#
- Title
- how to a equall to b in c#
- Category
- C#
- Title
- C# for
- Category
- C#
- Title
- c# EncoderParameter
- Category
- C#
- Title
- use newtonsoft json to clone object
- Category
- C#
- Title
- c# return two variables of different types
- Category
- C#
- Title
- length of a string c#
- Category
- C#
- Title
- wpf textblock line break code behind
- Category
- C#
- Title
- configure 1 to 1 relation ef
- Category
- C#
- Title
- math.pow in C# using loop
- Category
- C#
- Title
- c# random string
- Category
- C#
- Title
- unity detect any key
- Category
- C#
- Title
- how to insert into a list c#
- Category
- C#
- Title
- replace all ponctuation characters c#
- Category
- C#
- Title
- add mime type for woff in web.config
- Category
- C#
- Title
- how to select time and date in datetimepicker in c#
- Category
- C#
- Title
- What is a class in c#
- Category
- C#
- Title
- razor preview
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- C# enum
- Category
- C#
- Title
- how consider the first caracter in Split c#
- Category
- C#
- Title
- c# storing value in session
- Category
- C#
- Title
- convert base64 string to string c#
- Category
- C#
- Title
- how to convert from hexadecimal to binary in c#
- Category
- C#
- Title
- unity 2d Drag object
- Category
- C#
- Title
- invalidoperationexception c# ui thread
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- Unity C# instantiate prefab
- Category
- C#
- Title
- test how catch exception c#
- Category
- C#
- Title
- built in methods to order a list c#
- Category
- C#
- Title
- unity how to move an object to another object
- Category
- C#
- Title
- visual studio c# mark class deprecated
- Category
- C#
- Title
- c# date
- Category
- C#
- Title
- c# mailmessage set sender name
- Category
- C#
- Title
- c# check if argument null
- Category
- C#
- Title
- check if network is available c#
- Category
- C#
- Title
- c# how to compare 2 dates without time
- Category
- C#
- Title
- unity check if gameobject is active
- Category
- C#
- Title
- decimal to string whole number c#
- Category
- C#
- Title
- Execute code every x seconds with Update()
- Category
- C#
- Title
- c# quick "is" "as"
- Category
- C#
- Title
- C# get all child classes of a class
- Category
- C#
- Title
- select a whole row out of a 2d array C#
- Category
- C#
- Title
- c# ienumerable to list
- Category
- C#
- Title
- c# length 2d array
- Category
- C#
- Title
- unity set material color
- Category
- C#
- Title
- wpf restart application c#
- Category
- C#
- Title
- exception handling c#
- Category
- C#
- Title
- functions unity
- Category
- C#
- Title
- unity deactivate scripts in list
- Category
- C#
- Title
- unity get max occurrence in list
- Category
- C#
- Title
- how to use K2 games Games parallax background
- Category
- C#
- Title
- reverse a string in c#
- Category
- C#
- Title
- c# bool list count true
- Category
- C#
- Title
- multidimensional meaning
- Category
- C#
- Title
- how to insert <input> datatype <td> in asp.net core table
- Category
- C#
- Title
- c# check if string is all numbers
- Category
- C#
- Title
- visual studio C# hintergrund bild ändern
- Category
- C#
- Title
- unity collider2d contains point
- Category
- C#
- Title
- c# set textbox text
- Category
- C#
- Title
- c# inheritance constructor
- Category
- C#
- Title
- how to clamp transform.rotation
- Category
- C#
- Title
- c# change variable types
- Category
- C#
- Title
- F# convert generic.List to list
- Category
- C#
- Title
- c# discord bot
- Category
- C#
- Title
- c# float to string
- Category
- C#
- Title
- c# get hwid
- Category
- C#
- Title
- instantiate object in circle
- Category
- C#
- Title
- convert string to number C#
- Category
- C#
- Title
- string to uint c#
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- how to stream video from vlc in c#
- Category
- C#
- Title
- c# send email
- Category
- C#
- Title
- how to find object by ag unity
- Category
- C#
- Title
- xarray: create 2d dataset
- Category
- C#
- Title
- c# inline if
- Category
- C#
- Title
- how to print statement in c#
- Category
- C#
- Title
- c# filter non alphanumeric characters
- Category
- C#
- Title
- how to compare datetime in c#
- Category
- C#
- Title
- degree to radians c#
- Category
- C#
- Title
- asp.net core redirecttoaction with parameters
- Category
- C#
- Title
- uncaught syntaxerror invalid or unexpected token unity webgl
- Category
- C#
- Title
- c# append to file
- Category
- C#
- Title
- c# warning CS0108
- Category
- C#
- Title
- docker ssh
- Category
- C#
- Title
- c# param exception
- Category
- C#