how to add movement in unity
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private string moveInputAxis = "Vertical";
public float moveSpeed = 0.1f;
public Rigidbody rb;
public bool cubeIsOnTheGround = true;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float moveAxis = Input.GetAxis(moveInputAxis);
ApplyInput(moveAxis);
if(Input.GetButtonDown("Jump") && cubeIsOnTheGround == true)
{
rb.AddForce(new Vector3(0, 7, 0), ForceMode.Impulse);
cubeIsOnTheGround = false;
}
private void ApplyInput(float moveInput)
{
Move(moveInput);
}
private void Move(float input)
{
transform.Translate(Vector3.forward * input * moveSpeed);
}
private void OnCollisionEnter(Collision collision) {
if(collision.gameObject.tag == "Ground") {
cubeIsOnTheGround = true;
}
}
}
Also in C#:
- Title
- unity check if gameobject is active
- Category
- C#
- Title
- check if number is even or odd c#
- Category
- C#
- Title
- unity onclick object
- Category
- C#
- Title
- c# string contains space
- Category
- C#
- Title
- C# extend array
- Category
- C#
- Title
- import regex c#
- Category
- C#
- Title
- c# combobox datasource enum
- Category
- C#
- Title
- built in methods to order a list c#
- Category
- C#
- Title
- jump script unity 2d
- Category
- C#
- Title
- unity list
- Category
- C#
- Title
- mysql executeScalar only if successful
- Category
- C#
- Title
- can send but cannot receive email dreamhost email
- Category
- C#
- Title
- get set c#
- Category
- C#
- Title
- Length = '((System.Net.RequestStream)RequestStream).Length' threw an exception of type 'System.NotSupportedException'
- Category
- C#
- Title
- comments unity c#
- Category
- C#
- Title
- unity how to change the text on a button
- Category
- C#
- Title
- how to a equall to b in c#
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- unity making homing missile
- Category
- C#
- Title
- how to switch scenes unity
- Category
- C#
- Title
- change textbox location C#
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- how to get odd saturday in a month in c#
- Category
- C#
- Title
- convert from xls to xlsx C#
- Category
- C#
- Title
- c# create new object
- Category
- C#
- Title
- get web config key value in c# razor view
- Category
- C#
- Title
- why is c# say ; expected
- Category
- C#
- Title
- unity accessing 2d pointlight from c# script
- Category
- C#
- Title
- unity instantiate
- Category
- C#
- Title
- Unity if object doens't exist
- Category
- C#
- Title
- new command - latex
- Category
- C#
- Title
- iterate through dictionary c#
- Category
- C#
- Title
- unity collider2d contains point
- Category
- C#
- Title
- button commandfield commandargument pass textbox
- Category
- C#
- Title
- binding c#
- Category
- C#
- Title
- unity lerp
- Category
- C#
- Title
- unity create a child object
- Category
- C#
- Title
- how to set progress openedge driver name for odbc connection c#
- Category
- C#
- Title
- decalre an int list mvc
- Category
- C#
- Title
- how to get length of okobjectresult c#
- Category
- C#
- Title
- can't add an editor script
- Category
- C#
- Title
- decimals not stored in azure tables
- Category
- C#
- Title
- How to look at an object unity
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- c# catch two exceptions in one block
- Category
- C#
- Title
- convert array object to int[] c#
- Category
- C#
- Title
- nunit return parameter
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# winform remove button border
- Category
- C#
- Title
- c sharp if string equals
- Category
- C#
- Title
- c# 2 timespan return yesterday
- Category
- C#
- Title
- IEnumerator
- Category
- C#
- Title
- c# inotifypropertychanged best practices
- Category
- C#
- Title
- c# enum default
- Category
- C#
- Title
- c# fold list
- Category
- C#
- Title
- C# how to get public key for InternalsVisibleTo
- Category
- C#
- Title
- set object to random color unity
- Category
- C#
- Title
- c# to vb.net
- Category
- C#
- Title
- unity assign button onclick
- Category
- C#
- Title
- asp textarea
- Category
- C#
- Title
- c# array Reverse method
- Category
- C#
- Title
- json serialize object capitalization config
- Category
- C#
- Title
- math.pow in C# using loop
- Category
- C#
- Title
- ping with c#
- Category
- C#
- Title
- array c#
- Category
- C#
- Title
- c# how to initialize an array
- Category
- C#
- Title
- c sharp index of substring
- Category
- C#
- Title
- c# pull request
- Category
- C#
- Title
- Read csv file into wpf C#
- Category
- C#
- Title
- c# string array to string
- Category
- C#
- Title
- application variable in asp.net core
- Category
- C#
- Title
- how to allow user import image c#
- Category
- C#
- Title
- debug.log unity
- Category
- C#
- Title
- POST http://localhost:5001/api/v1/identity/login 500 (Internal Server Error) LoginForm.jsx:39 Error: Request failed with status code 500 at createError (createError.js:16) at settle (settle.js:17) at XMLHttpRequest.handleLoad (xhr.js:61)
- Category
- C#
- Title
- c# filter non alphanumeric characters
- Category
- C#
- Title
- cannot apply indexing with to an expression of type 'object'
- Category
- C#
- Title
- unity movetowards 2d
- Category
- C#
- Title
- unity prevent system from creation
- Category
- C#
- Title
- c# change variable types
- Category
- C#
- Title
- leantween id
- Category
- C#
- Title
- defualtsize UWP c#
- Category
- C#
- Title
- uwp roaming data sample
- Category
- C#
- Title
- C# get all child classes of a class
- Category
- C#
- Title
- how to close a windows form application in c#
- Category
- C#
- Title
- how to make infinite loop in c#
- Category
- C#
- Title
- unity timer with miliseconds
- Category
- C#
- Title
- .net identity seed users and roles
- Category
- C#
- Title
- how to generate random unique id in c#
- Category
- C#
- Title
- c# return multiple value unity
- Category
- C#
- Title
- c# round number
- Category
- C#
- Title
- how to clear console through script unity
- Category
- C#
- Title
- unity how to tell when a gameobject is colliding
- Category
- C#
- Title
- delay in unity
- Category
- C#
- Title
- asp.net mvc 5 codefirst dropdown list
- Category
- C#
- Title
- unity gameobjects with tag
- Category
- C#
- Title
- c# rsa example
- Category
- C#
- Title
- c# linq select specific columns
- Category
- C#
- Title
- get user directory of file in c#
- Category
- C#
- Title
- c# superclass constructor
- Category
- C#
- Title
- c# making a folder
- Category
- C#