Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5. using UnityEngine.Networking;
  6. using UnityEngine.UI;
  7.  
  8. public class Player : NetworkBehaviour
  9. {
  10. public LayerMask clickable;
  11. private NavMeshAgent player;
  12.  
  13. // Use this for initialization
  14. void Start ()
  15. {
  16. if(!isLocalPlayer)
  17. {
  18. Destroy(this);
  19. return;
  20. }
  21.  
  22. player = GetComponent<NavMeshAgent>();
  23. }
  24.  
  25. // Update is called once per frame
  26. void Update ()
  27. {
  28. // Right click to move to desired position
  29. if (Input.GetMouseButton(1))
  30. {
  31. Ray myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
  32. RaycastHit hitInfo;
  33.  
  34. if (Physics.Raycast(myRay, out hitInfo, 100, clickable))
  35. {
  36. player.SetDestination(hitInfo.point);
  37. }
  38. }
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement