unity mobile controls
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour {
//variables
public float moveSpeed = 300;
public GameObject character;
private Rigidbody2D characterBody;
private float ScreenWidth;
// Use this for initialization
void Start () {
ScreenWidth = Screen.width;
characterBody = character.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
int i = 0;
//loop over every touch found
while (i < Input.touchCount) {
if (Input.GetTouch (i).position.x > ScreenWidth / 2) {
//move right
RunCharacter (1.0f);
}
if (Input.GetTouch (i).position.x < ScreenWidth / 2) {
//move left
RunCharacter (-1.0f);
}
++i;
}
}
void FixedUpdate(){
#if UNITY_EDITOR
RunCharacter(Input.GetAxis("Horizontal"));
#endif
}
private void RunCharacter(float horizontalInput){
//move player
characterBody.AddForce(new Vector2(horizontalInput * moveSpeed * Time.deltaTime, 0));
}
}
Also in C#:
- Title
- c# error "The name 'ViewBag' does not exist in the current context"
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- .net core download image from url binary file
- Category
- C#
- Title
- convert string to boolean c#
- Category
- C#
- Title
- .net core get image from url
- Category
- C#
- Title
- matplotlib measure the width of text
- Category
- C#
- Title
- eventos c#
- Category
- C#
- Title
- c# LCP
- Category
- C#
- Title
- unity how to change rotation
- Category
- C#
- Title
- cannot convert string to generic type c#
- Category
- C#
- Title
- c# print expression tree
- Category
- C#
- Title
- dictionary c#
- Category
- C#
- Title
- how to make error sound c#
- Category
- C#
- Title
- get number of sundays in a month c#
- Category
- C#
- Title
- unity rotate object relative to camera
- Category
- C#
- Title
- unity get all by tag
- Category
- C#
- Title
- create char array c#
- Category
- C#
- Title
- count the number of notes in a given amount c#
- Category
- C#
- Title
- get web config key value in c# razor view
- Category
- C#
- Title
- C# check if is first run
- Category
- C#
- Title
- how to change scenes in unity
- Category
- C#
- Title
- idbset sqlquery
- Category
- C#
- Title
- clear combobox c#
- Category
- C#
- Title
- c#if
- Category
- C#
- Title
- compile in one single exe c#
- Category
- C#
- Title
- how to make % posibility to spawn an object C# in unity
- Category
- C#
- Title
- unity check when clicked on object
- Category
- C#
- Title
- csharp datetime string format
- Category
- C#
- Title
- c sharp list indexer
- Category
- C#
- Title
- uwp file open picker
- Category
- C#
- Title
- C# enum
- Category
- C#
- Title
- top down movement unity
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# cheat sheet
- Category
- C#
- Title
- lazy loading c#
- Category
- C#
- Title
- how to get value from object in c#
- Category
- C#
- Title
- unity line renderer position count
- Category
- C#
- Title
- unity c# set gameobject active
- Category
- C#
- Title
- c# empty IEnumerable
- Category
- C#
- Title
- c# enum.getvalues
- Category
- C#
- Title
- c# scene manager
- Category
- C#
- Title
- unity cast float to int
- Category
- C#
- Title
- c# listview
- Category
- C#
- Title
- how to make pressing enter an event in c#
- Category
- C#
- Title
- change z value unity
- Category
- C#
- Title
- c sharp string replace
- Category
- C#
- Title
- get hash c#
- Category
- C#
- Title
- unity up arrow input
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- how to add system.messaging c#
- Category
- C#
- Title
- c# clear console read chache
- Category
- C#
- Title
- how to get the last element in an array in c#
- Category
- C#
- Title
- c# generate random number
- Category
- C#
- Title
- create new object from generic c#
- Category
- C#
- Title
- how to add movement in unity
- Category
- C#
- Title
- x angle oes back after 90 unity
- Category
- C#
- Title
- how to make if statement c#
- Category
- C#
- Title
- c# get time
- Category
- C#
- Title
- convert array object to int[] c#
- Category
- C#
- Title
- c# read char
- Category
- C#
- Title
- unity c# get bool from another script
- Category
- C#
- Title
- C# random.Next error
- Category
- C#
- Title
- unity vector3 to array
- Category
- C#
- Title
- c# sort for loop
- Category
- C#
- Title
- unity detect number key
- Category
- C#
- Title
- c# unhandled exception in thread
- Category
- C#
- Title
- convert word files to plain text c#
- Category
- C#
- Title
- void start
- Category
- C#
- Title
- native-googlesignin configuration is null!?
- Category
- C#
- Title
- unity indestructible
- Category
- C#
- Title
- asp multi select dropdown
- Category
- C#
- Title
- how to declare a string c#
- Category
- C#
- Title
- c# global enumerator
- Category
- C#
- Title
- unity reset scene
- Category
- C#
- Title
- what is the or symbol in C#
- Category
- C#
- Title
- c# yield
- Category
- C#
- Title
- unity deactive all object in list
- Category
- C#
- Title
- cursorlockmode cannot be used as a method C#
- Category
- C#
- Title
- convert generic to type c#
- Category
- C#
- Title
- iteration c#
- Category
- C#
- Title
- c# check if string is in array
- Category
- C#
- Title
- linq c# where condition
- Category
- C#
- Title
- No context type was found in the assembly
- Category
- C#
- Title
- c# array to list
- Category
- C#
- Title
- read configuration workerservice
- Category
- C#
- Title
- c# return two variables of different types
- Category
- C#
- Title
- c# string remove special characters
- Category
- C#
- Title
- ubuntu: how to open the terminal from c#
- Category
- C#
- Title
- defining vectors in c#
- Category
- C#
- Title
- unity set sprite transparency
- Category
- C#
- Title
- datetitime contrusctor c#
- Category
- C#
- Title
- sum the digits in c#
- Category
- C#
- Title
- c# tuple access
- Category
- C#
- Title
- create object in c#
- Category
- C#
- Title
- c# int
- Category
- C#
- Title
- viewBag as a list
- Category
- C#
- Title
- check if enabled unity
- Category
- C#
- Title
- no overload for 'useItemOnSceneLoad' matches delegate 'UnityAction<Scene, LoadSceneMode>'
- Category
- C#
- Title
- c# check file exists
- Category
- C#
- Title
- c# singleton
- Category
- C#