Skip to main content

Posts

Showing posts from June 26, 2022

AWSD controller with c#

      using   UnityEngine ;   using   System.Collections ;   using   System.Collections.Generic ;     [ RequireComponent  ( typeof ( Rigidbody ) ) ]   public   class  PlayerController  :  MonoBehaviour  {         public   float  movementSpeed  =  5 . 0f ;         void  Start  ( )   {                 }             void  Update  ( )   {           Rigidbody rigidbody  =  GetComponent < Rigidbody > ( ) ;             if ( Input . GetKey ( KeyCode . W ) )   {              transform . position   +=  Vector3 . forward   *  Time . deltaTime   *  movementSpeed ;           }     ...

Simple swipe and tap on mobile phone

 Simple swipe and tap on mobile phone   private  Vector3 fp ;     //First touch position      private  Vector3 lp ;     //Last touch position      private   float  dragDistance ;    //minimum distance for a swipe to be registered        void  Start ( )      {         dragDistance  =  Screen . height   *   15   /   100 ;   //dragDistance is 15% height of the screen      }        void  Update ( )      {          if   ( Input . touchCount   ==   1 )   // user is touching the screen with a single touch          {             Touch touch  =  Input . GetTouch ( 0 ) ;   // get the touch              i...

How to create joystick in unity

Joystick in unity using  System . Collections ; using System . Collections . Generic ; using UnityEngine ; public class Joystick : MonoBehaviour { public Transform player ; public float speed = 5.0f ; private bool touchStart = false ; private Vector2 pointA ; private Vector2 pointB ; public Transform circle ; public Transform outerCircle ; // Update is called once per frame void Update ( ) { if ( Input . GetMouseButtonDown ( 0 ) ) { pointA = Camera . main . ScreenToWorldPoint ( new Vector3 ( Input . mousePosition . x , Input . mousePosition . y , Camera . main . transform . position . z ) ) ; circle . transform . position = pointA * - 1 ; outerCircle . transform . position = pointA * - 1 ; circle . GetComponent<SpriteRenderer>() . enabled = true ; outerCircle . GetComponent<SpriteRenderer>() . enabled = true ; } ...