Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question IDE0059 unused value assignment

Discussion in 'Scripting' started by metamodernity, May 10, 2024.

  1. metamodernity

    metamodernity

    Joined:
    Apr 30, 2024
    Posts:
    3
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor.Experimental.GraphView;
    4. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6.  
    7. public class PlayerController : MonoBehaviour
    8. {
    9.     Vector2 movementInput;
    10.     public float moveSpeed = 1f;
    11.  
    12.     public float collisionOffset = 0.05f;
    13.  
    14.     Rigidbody2D rb;
    15.  
    16.     public ContactFilter2D movementFilter;
    17.  
    18.     List<RaycastHit2D> castCollisions = new List<RaycastHit2D>();
    19.  
    20.  
    21.  
    22.     void Start()
    23.     {
    24.         rb = GetComponent<Rigidbody2D>();
    25.     }
    26.  
    27.  
    28.     private void FixedUpdate() {
    29.        
    30.             if (movementInput != Vector2.zero)
    31.             {
    32.  
    33.             bool success = TryMove(movementInput);
    34.  
    35.                 if (!success)
    36.                 {
    37.                     success = TryMove(new Vector2(movementInput.x, 0));
    38.                     if (!success)
    39.                     {
    40.  
    41.                        success = TryMove(new Vector2(0, movementInput.y));
    42.  
    43.  
    44.                     }
    45.  
    46.                 }
    47.             }
    48.         }
    49.  
    50.         private bool TryMove(Vector2 direction)
    51.         {
    52.             int count = rb.Cast(
    53.                    direction,      
    54.                    movementFilter,
    55.                    castCollisions,
    56.                    moveSpeed * Time.fixedDeltaTime + collisionOffset);
    57.             if (count == 0)
    58.             {
    59.                 rb.MovePosition(rb.position + direction * moveSpeed * Time.fixedDeltaTime);
    60.                 return true;
    61.  
    62.             }
    63.             else
    64.             {
    65.                 return false;
    66.             }
    67.         }
    68.         void OnMove(InputValue movementValue)
    69.         {
    70.             movementInput = movementValue.Get<Vector2>();
    71.         }
    72.     }
    73.  
    what i'm trying to do is to make a character slide off when it hits with a collider. And theres this thing that the line " success = TryMove(new Vector2(0, movementInput.y));" says that the unused value assignment; any tips? dont change the code significantly tho, thanks
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,905
    You assign to success a third time but you aren‘t using that variable afterwards, thus the assignment is pointless and not needed.
     
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,936
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,213