Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Private Field is assigned but its value is never used, but i use it

$
0
0
Hello everybody, i'm working on a 2D Platformer for Android and i've got a problem with my code it says i dont have the moveVelocity assigned but in my eyes i'm using the field later in my code. I don't know where the problem is. I hope you could help me out. I get this Error : Assets/Scripts/PlayerController.cs(8,16): warning CS0414: The private field`PlayerController.moveVelocity' is assigned but its value is never used Here is my Code : using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float moveSpeed; private float moveVelocity; private Rigidbody2D myRiBo; public Transform groundCheck; public float groundCheckRadius; public LayerMask whatIsGround; public bool isGrounded; private Animator myAnim; public Vector3 respawnPoint; public LevelManager theLevelManager; // Use this for initialization void Start () { myRiBo = GetComponent (); myAnim = GetComponent (); respawnPoint = transform.position; theLevelManager = FindObjectOfType (); } // Update is called once per frame void Update () { // Ground Check for the Player isGrounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround); Move (Input.GetAxisRaw ("Horizontal")); myAnim.SetFloat ("Speed", Mathf.Abs (myRiBo.velocity.x)); myAnim.SetBool ("Grounded", isGrounded); // Check wich direction the Player should look if (myRiBo.velocity.x > 0) { transform.localScale = new Vector3 (1f, 1f, 1f); } else if (myRiBo.velocity.x < 0) { transform.localScale = new Vector3 (-1f, 1f, 1f); } } public void Move (float moveInput) { moveVelocity = moveSpeed * moveInput; } // If player is Grounded and want to Jump then Change Gravity public void Jump () { if (isGrounded) { GetComponent().gravityScale *= -1; transform.Rotate(0, 180, 180); } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>