Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to move your character in unity 2d game

using UnityEngine;

public class PlayerMovement : MonoBehaviour  // PlayerMovement is the name of the script
{
    public float speed = 10;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        Vector2 pos = transform.position;

        pos.x += h * Time.deltaTime * speed;
        pos.y += v * Time.deltaTime * speed;

        transform.position = pos;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: difference between namespace and assembly in c# 
Csharp :: c# System.Resources.MissingManifestResourceException error 
Csharp :: c# run as administrator 
Csharp :: unity scenenmananger 
Csharp :: windows form textbox numbers only 
Csharp :: c# write to console 
Csharp :: c sharp gun shooting 
Csharp :: unity convert mouse position to world position in editor mode 
Csharp :: unity gameobject.findobjectswith tag set active 
Csharp :: contains with ignore case c# 
Csharp :: change scene unity 
Csharp :: c# array last element 
Csharp :: how to store more data than doublec# 
Csharp :: C# infinite clock coroutine loop 
Csharp :: c# get vector2 distance 
Csharp :: nepali phone number regex 
Csharp :: audiomixer get float 
Csharp :: unity length of string 
Csharp :: dapper delete where in list 
Csharp :: Codewars Multiply 
Csharp :: check if current time is in the morning c# 
Csharp :: clear array c# 
Csharp :: vb.net open file with default program 
Csharp :: exit a method c# 
Csharp :: blazor button onclick parameter 
Csharp :: c# sort array string by length 
Csharp :: conditional blazor styles 
Csharp :: unity up arrow input 
Csharp :: Xamarin.Forms - How to navigate to a tabbed page child page 
Csharp :: bootstrap modal 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =