User Tools

Site Tools


informatica:realidad_virtual:unity:3apersona

tags: 3apersona tercera 3a

Abrir puerta

Movimiento

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class CharacterMovementScript : MonoBehaviour
{
    public NavMeshAgent playerNavMeshAgent;

    public Camera playerCamera;

    public Animator playerAnimator;
    public bool isRunning;
    public bool isDeath;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        bool isDeath = playerAnimator.GetBool("isDeath");
        if (Input.GetMouseButton(0) && !isDeath)
        {
            Ray myRay = playerCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit myRaycastHit;

            if(Physics.Raycast(myRay, out myRaycastHit))
            {
                playerNavMeshAgent.SetDestination(myRaycastHit.point);

            }
        }

        if (playerNavMeshAgent.remainingDistance <= playerNavMeshAgent.stoppingDistance)
        {
            isRunning = false;
        }
        else
        {
            isRunning = true;
        }
        playerAnimator.SetBool("isRunning",isRunning);
    }

}
informatica/realidad_virtual/unity/3apersona.txt · Last modified: 2023/04/03 17:51 by jose