Unity Error CS0103: The name 'newRotation' does not exist in the current context

Asked

Viewed 417 times

0

I am following the series of Nils Nightmare Unity Training day and I am in video class 2, but when compiling gives this error: Error CS0103: The name 'newRotation' does not exist in the current context (CS0103) (Assembly-Csharp), line 62.
The code is from Playermovement.cs. Here’s the whole code:

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 answer

1

There’s a mistake on line 61

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

You wrote nevRotation for the variable name, and when you use it you use newRotation swap that nev for new that will solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.