unity 2d horizontal movement help
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f;
private float movement = 0f;
private Rigidbody2D rigidBody;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update()
{
movement = Input.GetAxis("Horizontal");
if (movement > 0f)
{
rigidBody.velocity = new Vector2(movement * speed, rigidBody.velocity.y);
}
else if (movement < 0f)
{
rigidBody.velocity = new Vector2(movement * speed, rigidBody.velocity.y);
}
else
{
rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);
}
}
}
Also in C#:
- Title
- tachyons
- Category
- C#
- Title
- Check object is in layermask unity
- Category
- C#
- Title
- unity timer
- Category
- C#
- Title
- socket in c#
- Category
- C#
- Title
- microsoft.portable.csharp.targets was not found vs 2019
- Category
- C#
- Title
- c# webrequest cookies
- Category
- C#
- Title
- how to make an object move in unity
- Category
- C#
- Title
- get random number c#
- Category
- C#
- Title
- open link c#
- Category
- C#
- Title
- how to print statement in c#
- Category
- C#
- Title
- what is a protected int c#
- Category
- C#
- Title
- unity list
- Category
- C#
- Title
- c# form set auto scale
- Category
- C#
- Title
- .net core download image from url binary file
- Category
- C#
- Title
- array copy c#
- Category
- C#
- Title
- epplus excel vb.net
- Category
- C#
- Title
- razor preview
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- how to convert float to int c#
- Category
- C#
- Title
- C# public 2d array
- Category
- C#
- Title
- How can you learn C# on your own
- Category
- C#
- Title
- how to make rb.addforce 2d
- Category
- C#
- Title
- unity face direction of movement
- Category
- C#
- Title
- unity calculate path
- Category
- C#
- Title
- vb.net tostring numeric format string
- Category
- C#
- Title
- c# resize image keep aspect ratio
- Category
- C#
- Title
- how to find a transform unity
- Category
- C#
- Title
- how to locate a specific element in a list c#
- Category
- C#
- Title
- linq query select top 1 c#
- Category
- C#
- Title
- c# math to radiant
- Category
- C#
- Title
- asp net mvc 5 return view from another controller
- Category
- C#
- Title
- C# Into To Tring Debug.Log
- Category
- C#
- Title
- C# get object property name
- Category
- C#
- Title
- unity cast float to int
- Category
- C#
- Title
- C# .net core convert int to enum
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- how to move towards an object unity
- Category
- C#
- Title
- internal c#
- Category
- C#
- Title
- animator hash in unity
- Category
- C#
- Title
- class selector to property in asp net core dropdown
- Category
- C#
- Title
- override Microsoft.AspNetCore.Authorization.AuthorizeAttribute
- Category
- C#
- Title
- c# return two variables of different types
- Category
- C#
- Title
- how to turn a string in a char list c#
- Category
- C#
- Title
- unity how to set an objects postion x,y,z
- Category
- C#
- Title
- remove all array elements c#
- Category
- C#
- Title
- foreach syntax c#
- Category
- C#
- Title
- c# keyvaluepair
- Category
- C#
- Title
- c# if statement
- Category
- C#
- Title
- javascript append
- Category
- C#
- Title
- how to delay something in c# unity
- Category
- C#
- Title
- how to see if they are aholding down a key unity
- Category
- C#
- Title
- c# for loop without increment
- Category
- C#
- Title
- what function is called just before the a script is ended c#
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- Exception thrown: 'System.FormatException' in mscorlib.dll dates
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- C# foreach loop async but wait at end
- Category
- C#
- Title
- covert char[] to string C#
- Category
- C#
- Title
- bulk update in c# using jquery datatble
- Category
- C#
- Title
- How to search for a string from readline in c#
- Category
- C#
- Title
- transform object according to its parent unity
- Category
- C#
- Title
- get string character by index c#
- Category
- C#
- Title
- how to add a gameobject
- Category
- C#
- Title
- c# reverse array
- Category
- C#
- Title
- list.addrange in c#
- Category
- C#
- Title
- unity rotate around axis
- Category
- C#
- Title
- How to execute script in C#
- Category
- C#
- Title
- .net loop through dictionary
- Category
- C#
- Title
- how to raycast unit
- Category
- C#
- Title
- how to flip selection in aseprite
- Category
- C#
- Title
- vb.net check if datatable has rows
- Category
- C#
- Title
- list of vectors c#
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- assign datasource to dropdownlist in c#
- Category
- C#
- Title
- c# polymorphism
- Category
- C#
- Title
- how to initiate a varaible in cs
- Category
- C#
- Title
- how to get specific length of row in matrix c#
- Category
- C#
- Title
- linq c# object except two lists
- Category
- C#
- Title
- how to mock abstract httpcontext using moq .net core
- Category
- C#
- Title
- first person camera controller unity
- Category
- C#
- Title
- unity ui not seen
- Category
- C#
- Title
- c# index in select
- Category
- C#
- Title
- how can convert string to int csharp
- Category
- C#
- Title
- how to update modal class using dbfirst in asp.net core
- Category
- C#
- Title
- unity deactivate scripts in list
- Category
- C#
- Title
- c# get foreground window
- Category
- C#
- Title
- c# get index of item in list
- Category
- C#
- Title
- unity 2d Drag object
- Category
- C#
- Title
- what is using static in c#
- Category
- C#
- Title
- unity clamp rotation
- Category
- C#
- Title
- Assets/Scripts/Snake.cs(177,25): error CS1061: Type `Snake.SnakeBodyPart' does not contain a definition for `SetGridPostion' and no extension method `SetGridPostion' of type `Snake.SnakeBodyPart' could be found. Are you missing an assembly reference?
- Category
- C#
- Title
- what type of variable is true or false in c#
- Category
- C#
- Title
- c# get country code
- Category
- C#
- Title
- Unity how to put IEnumerator in update and loop once with yeild return new waitforseconds
- Category
- C#
- Title
- webclient c# example post
- Category
- C#
- Title
- c# find element by condition
- Category
- C#
- Title
- creating a c# class
- Category
- C#
- Title
- how to wait in c#
- Category
- C#
- Title
- c# convert list to string
- Category
- C#
- Title
- max of array C#
- Category
- C#