Search Unity

Question sprite isnt showing

Discussion in '2D' started by unity_005946E12C5F7D78583B, Aug 12, 2023.

  1. unity_005946E12C5F7D78583B

    unity_005946E12C5F7D78583B

    Joined:
    Dec 19, 2022
    Posts:
    35
    for some reason a sprite in my game isnt appearing when i hit play, it appears in the scene but turns invisible when i test the game
    this is the code it has
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. public class mouse : MonoBehaviour
    6. {
    7.    public InputActionReference mouses;
    8.    public List<playerMovement> player = new List<playerMovement>();
    9.    public SpriteRenderer sprite;
    10.  
    11.     // Update is called once per frame
    12.     void Update()
    13.     {
    14.         transform.position = Camera.main.ScreenToWorldPoint(mouses.action.ReadValue<Vector2>());
    15.  
    16.         if (player[0].dragging == true && player[0].candash == true)
    17.         {
    18.             sprite.enabled = true;
    19.         }
    20.          else
    21.          {
    22.             sprite.enabled = false;
    23.          }
    24.  
    25.     }
    26. }
    dragging is just a variable that activates when i click and hold on the player and candash is, by default, true, i tried checking the exporting, the object, the code, the animator and i cant find anything that makes the object disappear when tested, does anybody know why this happens?