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 :: linq contains null 
Csharp :: c# wtssendmessage 
Csharp :: ASP.Net MVC 5 datalist event trap to perform action 
Csharp :: convert excel to datatable without xml configuration 
Csharp :: sterge element din coada c# 
Csharp :: c# download image from url 
Csharp :: player not following slide object unity 2d 
Csharp :: print the top view of the binary tree 
Csharp :: go down a line in <summary dotnet 
Csharp :: how to take previous record in linq c# 
Csharp :: C# WriteLine() and Write() 
Csharp :: how to check if string from textbox exists in db 
Csharp :: generate an mvc controller when dotnet core command line 
Csharp :: custom convert list object to other object c# 
Csharp :: resize image and add watermark c# 
Csharp :: slider script unity 
Csharp :: c# switch expression 8.0 
Csharp :: .net 6 foreach only if not null 
Csharp :: c# odd or even 
Csharp :: creating weighted graph in c# 
Csharp :: IdentityServer vs JWT vs OAuth? 
Csharp :: c# printwindow chrome 
Csharp :: ExceptionFilterAttribute exception-handler-middleware-not-catching 
Csharp :: kendo razor textbox 
Csharp :: Get mac address of Device - NAYCode.com 
Csharp :: client = matrice[indexselectedclient] as String[]; 
Csharp :: c# is not 
Csharp :: c# url relative path remove 
Csharp :: one to many relationship in asp net entity framework with role 
Csharp :: asp.net core mvc not triggering client side validation 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =