Advertisement
Guest User

BUG !

a guest
Oct 17th, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class PlayerMovement : MonoBehaviour
  7. {
  8. public Camera cam;
  9. public NavMeshAgent player;
  10. public Animator playerAnimator;
  11. public GameObject targetDest;
  12.  
  13.     // Start is called before the first frame update
  14.     void Start()
  15.     {
  16.         targetDest.SetActive(false);
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update()
  21.     {
  22.    
  23.     float distance = Vector3.Distance(player.transform.position, targetDest.transform.position);
  24.    
  25.         if(Input.GetMouseButtonDown(0))
  26.         {
  27.             Ray ray = cam.ScreenPointToRay(Input.mousePosition);
  28.             RaycastHit hitPoint;
  29.  
  30.         if(Physics.Raycast(ray, out hitPoint))
  31.         {
  32.             targetDest.transform.position = hitPoint.point;
  33.             player.SetDestination(hitPoint.point);
  34.         }
  35.        
  36.         }
  37.    
  38.     if (player.velocity != Vector3.zero)
  39.     {
  40.         targetDest.SetActive(true);
  41.         playerAnimator.SetBool("isWalking", true);
  42.     }
  43.     if (distance < 1.5f)
  44.     {
  45.         targetDest.SetActive(false);
  46.         playerAnimator.SetBool("isWalking", false);
  47.     }
  48.    
  49.     }
  50. }
Tags: Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement