Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity topdown

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class 2dMovement : MonoBehaviour
{
  //This also works with joystick, PS this is topdown movement

 private Rigidbody2D rb;
 public float MoveSpeed = 15f;


 void Start ()
 {
   rb = GetComponent<Rigidbody2D>(); 
 }

 void Update ()
 {
    private float vertical;
    private float horizontal; 
 
    horizontal = Input.GetAxisRaw("Horizontal");
    vertical = Input.GetAxisRaw("Vertical"); 
 }

 private void FixedUpdate()
 {  
    rb.velocity = new Vector2(horizontal * MoveSpeed, vertical * MoveSpeed);
 }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity joystick movement 2d 
Csharp :: how to print dictionary in c# 
Csharp :: c# create object with properties 
Csharp :: C# How to read users input and display it 
Csharp :: c# check if 2d array position exists 
Csharp :: increase timeout in .net core web app 
Csharp :: c# list to array 
Csharp :: c# string array contains 
Csharp :: get current assembly path c# 
Csharp :: randomm number from 2 different ranges 
Csharp :: two variable in one loop c# 
Csharp :: asp.net core 3.1 ajax partial view 
Csharp :: unity debug c# code with console 
Csharp :: unity check if other object is colliding 
Csharp :: blazor swagger setup 
Csharp :: xamarin forms open new page on button click 
Csharp :: c# distinct by property 
Csharp :: total months between two dates c# 
Csharp :: unity rotate direction by angle 
Csharp :: c# datetime add 
Csharp :: contains char c# 
Csharp :: unity exception 
Csharp :: c# regex find number in string 
Csharp :: remove adjacent duplicate characters 
Csharp :: play animation through script unity 
Csharp :: difference between class and struct in c# 
Csharp :: c# dictionary values to list 
Csharp :: wpf messagebox result 
Csharp :: c# insert spaces before capital letters 
Csharp :: asp.net core mvc jsonresult example 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =