unity 2d horizontal movement help
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#:
- xarray: create 2d dataset
- unity html get request
- c# resize image keep aspect ratio
- setting the parent of a transform which resides in a prefab
- C# previous method
- unity multiply xyz of two vectors
- Unity if object doens't exist
- C# resize window without title bar
- linq in c#
- how to convert object in string JSON c#
- unity accessing 2d pointlight from c# script
- c# webrequest cookies
- application.stop unity
- unity get velocity at point
- The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.
- c# how to use inovke
- unity array of child objects
- player script unity
- .net loop through dictionary
- c# string remove special characters
- get all child gameObject of gameObject C#
- read embedded resource c# xml
- internal c#
- c# try catch error