Advertisement
Guest User

Untitled

a guest
Jan 14th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.     private PhotonView PV;
  2.     public float movementSpeed;
  3.     private float rotationSpeed = 400;
  4.     private Joystick joystick;
  5.     private Rigidbody rb;
  6.  
  7.     void Start ()
  8.     {
  9.         PV = GetComponent<PhotonView>();
  10.         joystick = TempData.Instance.GetJoystick();
  11.         rb = GetComponent<Rigidbody>();
  12.     }
  13.    
  14.     void Update () {
  15.         if (PV.IsMine)
  16.         {
  17.             Move();
  18.         }
  19.     }
  20.  
  21.     public void Move()
  22.     {
  23.         if (joystick.Vertical != 0 && joystick.Horizontal != 0)
  24.         {
  25.             transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(new Vector3(joystick.Horizontal,      0f, joystick.Vertical)),
  26.                 rotationSpeed * Time.deltaTime);
  27.        
  28.             rb.velocity = new Vector3(joystick.Horizontal * movementSpeed, rb.velocity.y,
  29.                 joystick.Vertical * movementSpeed);
  30.         }
  31.     }
  32.  
  33.     public void Throw()
  34.     {
  35.         PV.RPC("RPC_Throw", RpcTarget.All);
  36.     }
  37.  
  38.     [PunRPC]
  39.     private void RPC_Throw()
  40.     {
  41.         PhotonNetwork.Instantiate(Path.Combine("Prefabs", "Item"), transform.position,
  42.             transform.rotation, 0);
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement