Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- public class PlayerMovement : MonoBehaviour
- {
- public Camera cam;
- public NavMeshAgent player;
- public Animator playerAnimator;
- public GameObject targetDest;
- // Start is called before the first frame update
- void Start()
- {
- targetDest.SetActive(false);
- }
- // Update is called once per frame
- void Update()
- {
- float distance = Vector3.Distance(player.transform.position, targetDest.transform.position);
- if(Input.GetMouseButtonDown(0))
- {
- Ray ray = cam.ScreenPointToRay(Input.mousePosition);
- RaycastHit hitPoint;
- if(Physics.Raycast(ray, out hitPoint))
- {
- targetDest.transform.position = hitPoint.point;
- player.SetDestination(hitPoint.point);
- }
- }
- if (player.velocity != Vector3.zero)
- {
- targetDest.SetActive(true);
- playerAnimator.SetBool("isWalking", true);
- }
- if (distance < 1.5f)
- {
- targetDest.SetActive(false);
- playerAnimator.SetBool("isWalking", false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement