Somebody help me something is wrong here there are 3 mistakes and I don’t know how to get them out! C#

Asked

Viewed 88 times

-2

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    //Velocidade do Jogador
    public float speed = 6f;

    //Vetor responsavel pelo movimento
    Vector3 movement;
    //Responsavel pela transliçao da animaçao
    Animator anim;
    //Responsavel pela fisica do objeto
    Rigidbody playerRigidbody;
    // Mascara de chao
    int floorMask;
    //Inf para raycast
    float camRayLenght = 100f;

    void Awake()
    {
        floorMask = LayerMask.GetMask ("Floor");

        //atribuir as referencias
        anim = GetComponents <Animator> ();
        playerRigidbody = GetComponent <Rigidbody> ();

    }

    void FixedUpdate()
    {
        float h = Input.GetAxisRaw ("Horizontal");
        float v = Input.GetAxisRaw ("Vertical");

        movement (h, v);
        Turning ();
        Animating(h,v);

    }


    //movimento
    void move (float h, float v)
    {
        //dertemina o movimento
        movement.Set (h,0f,v);

        //normaliza o movimento
        movement = movement.normalized * speed * Time.deltaTime;

        //efetua o movimento no personagem
        playerRigidbody.MovePosition (transform.position + movement);
    }


    //girar o jogador
    void Turning()
    {
        Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);

        RaycastHit floorHit;

        if(Physics.Raycast(camRay,out floorHit,camRayLenght,floorMask))
        {
            Vector3 playerToMouse = floorHit.point - Transform.position;
            playerToMouse.y = 0f;

            Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
            playerRigidbody.MoveRotation(newRotation);


        }


}

    void Animating(float h, float v)
    {
        bool walking = h != 0f || v!=0f;
        anim.SetBool ("IsWalkin", walking);


    }

}
  • Your question is looking like one of those pastimes you see in magazines: Discover the 6 differences

  • 3

    If you have the error messages, edit the question and add them or describe the unexpected result and what would be the right one.

1 answer

2


From what I can see, first mistake is in:

anim = GetComponents <Animator> ();

that should be:

anim = GetComponent <Animator> ();

The second mistake is in:

movement (h, v);

that should be:

move (h, v);

The third mistake is in:

Vector3 playerToMouse = floorHit.point - Transform.position;

that should be:

Vector3 playerToMouse = floorHit.point - transform.position;

This fixes the errors, but I can’t guarantee that the logic of the script is correct.

Browser other questions tagged

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