0

Estou acompanhando a série do Nils Nightmare Unity Training day e estou na videoaula 2, mas na hora de compilar dá esse erro: Error CS0103: O nome 'newRotation' não existe no contexto atual (CS0103) (Assembly-CSharp), linha 62.
O código é o do PlayerMovement.cs. Aqui está o código todo:

1
2 public class PlayerMovement : MonoBehaviour
3  {
4
5   public float speed = 6f;                      // Velocidade do Jogador
6                                               
7   Vector3 movement;                            // Vetor responsavel pelo   movimento
8   Animator anim;                               // Responavel pela transicao da animacao
9   Rigidbody playerRigidbody;                   // Responsavel pela fisica do objeto
10  int floorMask;                               // Mascara de chao
11  float camRayLenght = 100f;                   // Inf para raycast
12
13  void Awake()
14  {
15      floorMask = LayerMask.GetMask ("Floor");
16
17      //Atribuir as referencias
18      anim = GetComponent <Animator> ();
19      playerRigidbody = GetComponent <Rigidbody> ();
20
21
22  }
23
24  void FixedUpdate()
25  {
26      float h = Input.GetAxisRaw ("Horizontal");
27      float v = Input.GetAxisRaw ("Vertical");
28
29      Move (h,v);
30      Turning ();
31      Animating (h, v);
32
33  }
34
35  // Movimento
36  void Move (float h, float v)
37  {
38      // Determina o movimento
39      movement.Set (h,0f,v);
40
41      // Normaliza o movimento
42      movement = movement.normalized * speed * Time.deltaTime;
43
44      // Efetua o movimento no personagem
45      playerRigidbody.MovePosition (transform.position + movement);
46
47  }
48
49  // Girar o jogador
50  void Turning ()
51  {
52      Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
53
54      RaycastHit floorHit;
55
56      if(Physics.Raycast(camRay,out floorHit,camRayLenght,floorMask))
57      {
58          Vector3 playerToMouse = floorHit.point - transform.position;
59          playerToMouse.y = 0f;
60
61          Quaternion nevRotation = Quaternion.LookRotation(playerToMouse);
62          playerRigidbody.MoveRotation(newRotation);
63
64
65
66      }
67
68  }
69
70  void Animating(float h, float v)
71  {
72      bool walking = h != 0f || v!=0f;
73      anim.SetBool("IsWalking", walking);
74
75  }
76  
77 }

1 Resposta 1

1

Tem um errinho na linha 61

61          Quaternion nevRotation = Quaternion.LookRotation(playerToMouse);
62          playerRigidbody.MoveRotation(newRotation);

Você escreveu nevRotation para o nome da variável, e quando você usa ela você usa newRotation troque aquele nev por new que vai resolver.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .