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 :: how set function when props update in vue 
Csharp :: c# string to variable name 
Csharp :: c# declare an int list 
Csharp :: how to create a file through c# script 
Csharp :: javascript close page after 5 seconds 
Csharp :: return json from controller c# 
Csharp :: how to print hello world in c# 
Csharp :: c# join string array 
Csharp :: c# array to list 
Csharp :: how to print using C# 
Csharp :: two variable in one loop in one line c# 
Csharp :: solidity get address of contract 
Csharp :: log to console c# unity 
Csharp :: how to set unique constraint from EF core 
Csharp :: serilog set log level 
Csharp :: c# find largest number in list 
Csharp :: c# array to string 
Csharp :: unity pick random number 
Csharp :: unity how to move an object 
Csharp :: c# update control from another thread 
Csharp :: inline creation dictionnary C# 
Csharp :: process.start web 
Csharp :: optimistic update 
Csharp :: how to add item in list at first position c# 
Csharp :: convert string to number c# 
Csharp :: c# how to find character in string 
Csharp :: c# space as string 
Csharp :: .net core copy directory to output 
Csharp :: c# escape characters 
Csharp :: round decimal two places 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =