Je suis en train de créer un jeu 2D "point and click" pour une thèse. Mais je débute en programmation. Je m'aide de tutos. Pour le déplacement à la souris je me suis appuyée sur ce tuto : https://www.youtube.com/watch?v=KU2CKBlCAxQ
Celui-ci fonctionne très bien mais que dans un environnement 3D. Si j'applique le script à mon projet 2D, rien ne se passe.
Voici le script en question :
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class MoveToClickPoint : MonoBehaviour {
public LayerMask WhatCanBeClickedOn;
private NavMeshAgent myAgent;
void Start() {
myAgent = GetComponent<NavMeshAgent>();
}
void Update() {
if (Input.GetMouseButtonDown(0)) {
Ray myRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(myRay, out hitInfo, 100, WhatCanBeClickedOn)) {
myAgent.SetDestination (hitInfo.point);
}
}
}
}
.