Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

basic movement script unity

public float speed = 5;

void Update() {
    float x = Input.GetAxisRaw("Horizontal");
    float y = Input.GetAxisRaw("Vertical");     
    gameObject.transform.Translate(new Vector3(x,y,0) * speed * Time.deltaTime);
}
Comment

unity movement

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

unity ui movement

//You can do something like applying a force to a rigidbody or do something like this

        float singleStep = 1f * Time.deltaTime;
        Vector3 LookDir = new Vector3(LookJoystick.Horizontal, 0, LookJoystick.Vertical);
        Vector3 newDirection = Vector3.RotateTowards(transform.forward, -LookDir, singleStep, 0.0f);
        transform.rotation = Quaternion.LookRotation(+newDirection);//but that has limits

also make sure you have this asset installed
Comment

PREVIOUS NEXT
Code Example
Csharp :: 2d topdown movement unity 
Csharp :: untiy instanciate prefab 
Csharp :: how to make a mouse down condition in C# 
Csharp :: excel which style property define background color in c# 
Csharp :: how to say hello world in c# 
Csharp :: c# add picturebox to form 
Csharp :: todictionary c# 
Csharp :: find-text-in-string-with-c-sharp 
Csharp :: discord bot in c# 
Csharp :: c# convert split to list 
Csharp :: c# current dir 
Csharp :: forech unity 
Csharp :: c# bytes to image 
Csharp :: c# web api return image file 
Csharp :: C# Unit test IConfiguration 
Csharp :: unity key up 
Csharp :: replace index in string c# 
Csharp :: o(n*m) 
Csharp :: response redirect new tab 
Csharp :: list index out of range c# 
Csharp :: unity cap fps 
Csharp :: unity actions 
Csharp :: unity button onclick 
Csharp :: HOW TO RETURN CELL VALUE FROM EXCEL IN C# 
Csharp :: remove all non alphabetic characters from string c# 
Csharp :: difference between class and struct 
Csharp :: c# break from foreach method 
Csharp :: c# read last 10 lines of file 
Csharp :: c# multi assignment 
Csharp :: dotnet automapper.extensions.microsoft.dependencyinjection 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =